GET ACCESS TOKEN GOOGLE API PHP

Complete the steps described in the rest of this page lớn create a simple PHPhường command-line application that makes requests khổng lồ the People API.

Bạn đang xem: Get access token google api php

Prerequisites

To run this quickstart, you need the following prerequisites:

PHP 5.4 or greater with the command-line interface (CLI) & JSON extension installed The Composer dependency management tool A obatambeienwasirherbal.com tài khoản

Step 1: Turn on the People API

Cliông chồng this button to create a new Cloud Platsize project & automatically enable the People API:

Enable the People API

In resulting dialog cliông chồng DOWNLOAD CLIENT CONFIGURATION và save sầu the file credentials.json to lớn your working directory.

Step 2: Install the obatambeienwasirherbal.com Client Library

composer require obatambeienwasirherbal.com/apiclient:^2.0

See the library's installation page for the alternative installation options.

Step 3: Set up the sample

Create a tệp tin named quickstart.php in your working directory and copy in the following code:


people/quickstart/quickstart.php
View on GitHub
return obatambeienwasirherbal.com_Client the authorized client object */ function getClient() // If there is no previous token or it's expired. if ($client->isAccessTokenExpired()) else } // Save sầu the token khổng lồ a file. if (!file_exists(dirname($tokenPath))) file_put_contents($tokenPath, json_encode($client->getAccessToken())); } return $client; } // Get the API client and construct the service object. $client = getClient(); $service = new obatambeienwasirherbal.com_Service_PeopleService($client); // Print the names for up to 10 connections. $optParams = array( 'pageSize' => 10, 'personFields' => 'names,emailAddresses', ); $results = $service->people_connections->listPeopleConnections('people/me', $optParams); if (count($results->getConnections()) == 0) else else } }

Step 4: Run the sample

Run the sample using the following command:

php quickstart.php

The first time you run the sample, it will prompt you to authorize access:

Browse to lớn the provided URL in your website browser.

If you are not already signed in to lớn your obatambeienwasirherbal.com trương mục, you are be prompted lớn sign in. If you are signed in to multiple obatambeienwasirherbal.com accounts, you are asked lớn select one trương mục to use for the authorization.

Clichồng the Accept button. Copy the code you're given, paste it inkhổng lồ the command-line prompt, and press Enter.

Notes

Authorization information is stored on the file system, so subsequent executions will not prompt for authorization. The authorization flow in this example is designed for a command-line application. For information on how lớn perform authorization in a website application, see Using OAuth 2.0 for Web Server Applications.

Troubleshooting

This section describes some comtháng issues that you may encounter while attempting khổng lồ run this quickstart và suggests possible solutions.

Xem thêm: tải game xuống máy tính

SSL certificate problem: unable to lớn get local issuer certificate

This error indicates that the underlying HTTPhường libraries can't find a certificate store, and are therefore unable to thiết đặt the SSL connection lớn obatambeienwasirherbal.com's servers. See the Guzzle library's documentation for information on how lớn thiết đặt a certificate store on your machine.

Uncaught InvalidArgumentException: missing the required redirect URI

This error occurs when the credentials.json file used contains a client ID of the wrong type. This code requires an OAuth client ID of type Other, which will be created for you when using the button in Step 1. If creating your own client ID please ensure you select the correct type.

This ứng dụng isn"t verified

If the OAuth consent screen displays the warning "This app isn't verified," your app is requesting scopes that provide access to lớn sensitive sầu user data. If your application uses sensitive scopes, your your phầm mềm must go through the verification process khổng lồ remove that warning and other limitations. During the development phase you can continue past this warning by clicking Advanced > Go lớn (unsafe).

Further reading

obatambeienwasirherbal.com APIs Client for PHPhường documentation People API PHPhường reference documentation
<,,,,> <,,>

Except as otherwise noted, the content of this page is licensed under the Creative sầu Commons Attribution 4.0 License, và code samples are licensed under the Apabịt 2.0 License. For details, see the obatambeienwasirherbal.com obatambeienwasirherbal.com Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2021-03-29 UTC.

*
Staông chồng Overflow

Terms

obatambeienwasirherbal.com API Services: User Data Policy

Programs

Women Techmakers obatambeienwasirherbal.com Developer Groups obatambeienwasirherbal.com obatambeienwasirherbal.com Experts Accelerators Developer Student Clubs

Developer consoles

obatambeienwasirherbal.com API Console obatambeienwasirherbal.com Cloud Platkhung Console obatambeienwasirherbal.com Play Console Firebase Console Actions on obatambeienwasirherbal.com Console Cast SDK Developer Console Chrome Web Store Dashboard
*
Android Chrome Firebase obatambeienwasirherbal.com Cloud Platkhung All products Terms Privacy Sign up for the obatambeienwasirherbal.com obatambeienwasirherbal.com newsletter Subscribe Language English Bahasa Indonesia Deutsch Español Français Português – Brasil Русский 中文 – 简体 日本語 한국어