Google People / Google Contacts API失败

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...

php
dongwen7380
dongwen7380 我做到了。我按照说明操作,我有$clientId和$clientSecret,但我仍然有同样的错误。看来这个错误是由另一个问题造成的。我不知道。
接近 2 年之前 回复
dongya6997
dongya6997 您是否阅读了错误消息中提供的链接
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问