rapidwebltd / php-google-people-api

👥 This package provides a user friendly way of interacting with Google Contacts via the Google People API.
GNU Lesser General Public License v3.0
100 stars 39 forks source link

I am getting an error code related to authorization could help me in this #18

Open jaylab1 opened 5 years ago

jaylab1 commented 5 years ago

<?php session_start();

ini_set('display_errors', 1); error_reporting(E_ALL ^ E_NOTICE);

require_once 'vendor/autoload.php';

use RapidWeb\GoogleOAuth2Handler\GoogleOAuth2Handler; use RapidWeb\GooglePeopleAPI\GooglePeople;

$clientId = '****-ip6c43oo3cs0ifqp4dmllbt48d5qo5jn.apps.googleusercontent.com'; $clientSecret = '***'; $refreshToken = ''; $scopes = ['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/contacts', 'https://www.googleapis.com/auth/contacts.readonly'];

$googleOAuth2Handler = new GoogleOAuth2Handler($clientId, $clientSecret, $scopes, $refreshToken);

$people = new GooglePeople($googleOAuth2Handler);

// Retrieval all contacts foreach($people->all() as $contact) { echo $contact->resourceName.' - '; if ($contact->names) { echo $contact->names[0]->displayName; } echo PHP_EOL; }

?>

Here is the error i am getting

Fatal error: Uncaught exception 'Exception' with message '{ "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED" } } ' in /home/newrsczn/public_html/ragtime.media/ADMIN/google/vendor/rapidwebltd/php-google-people-api/src/GooglePeople.php:63 Stack trace: #0 /home/newrsczn/public_html/ragtime.media/ADMIN/google/contact.php(27): RapidWeb\GooglePeopleAPI\GooglePeople->all() #1 {main} thrown in /home/newrsczn/public_html/ragtime.media/ADMIN/google/vendor/rapidwebltd/php-google-people-api/src/GooglePeople.php on line 63

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/74800667-i-am-getting-an-error-code-related-to-authorization-could-help-me-in-this?utm_campaign=plugin&utm_content=tracker%2F87779827&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F87779827&utm_medium=issues&utm_source=github).
m2k6artworks commented 4 years ago

I have the same problem. When I run the setup.php via cmd and follow the step. My refresh token are always NULL.

So I try to open the file ('..vendor\rapidwebltd\php-google-oauth-2-handler\src\GoogleOAuth2Handler.php') and edit the script

I change the code in line 33 with this (replace the string with your own uri): $this->client->setRedirectUri('http://localhost/peopleapi/');

I change the code in line 35 with this : $this->client->setApprovalPrompt('select_account consent');

Now try run the setup.php again via cmd and follow the step