简体   繁体   English

Google People / Google Contacts API 失败

[英]Google People / Google Contacts API Failed

I'm using this library : https://github.com/rapidwebltd/php-google-people-api我正在使用这个库: 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...谢谢你...

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.并授予您的 Google 帐户权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM