Reputation: 5525
I'm using this library : https://github.com/rapidwebltd/php-google-people-api
here's my code :
<?php
require_once __DIR__ . '/vendor/autoload.php';
use RapidWeb\GooglePeopleAPI\GooglePeople;
use RapidWeb\GoogleOAuth2Handler\GoogleOAuth2Handler;
$clientId = '***-***.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);
$contacts = $people->all();
print_r($contacts);
?>
and I got this following error :
[fivesta1@sg21 googlecontacts]$ php create_contact.php
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/fivesta1/public_html/googlecontacts/vendor/rapidwebltd/php-google-people-api/src/GooglePeople.php:63
Stack trace:
#0 /home/fivesta1/public_html/googlecontacts/create_contact.php(16): RapidWeb\GooglePeopleAPI\GooglePeople->all()
#1 {main}
thrown in /home/fivesta1/public_html/googlecontacts/vendor/rapidwebltd/php-google-people-api/src/GooglePeople.php on line 63
what did I miss here? thank you...
Upvotes: 0
Views: 532
Reputation: 11
I had the same error and it's because your refresh token expires. You have to run the setup again:
php vendor/rapidwebltd/php-google-oauth-2-handler/src/setup.php
And give permission to your Google Account.
Upvotes: 1