【问题标题】:Google People / Google Contacts API FailedGoogle 人员/Google 通讯录 API 失败
【发布时间】:2018-11-06 11:38:12
【问题描述】:

我正在使用这个库:https://github.com/rapidwebltd/php-google-people-api

这是我的代码:

<?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);

?>

我收到以下错误:

[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

我在这里错过了什么?谢谢...

【问题讨论】:

  • 我做到了。我按照说明操作,我有 $clientId 和 $clientSecret 但我仍然遇到同样的错误。看来这个错误是由另一个问题引起的。我不知道。

标签: php google-contacts-api google-people-api


【解决方案1】:

我遇到了同样的错误,这是因为您的刷新令牌已过期。您必须再次运行设置:

php vendor/rapidwebltd/php-google-oauth-2-handler/src/setup.php

并授予您的 Google 帐户权限。

【讨论】:

    猜你喜欢
    • 2016-07-23
    • 1970-01-01
    • 2014-11-30
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多