Dan*_*ker 6 php google-oauth google-api-php-client google-people-api
我正在尝试使用 Google People API 添加和更新我的 Google 联系人。我已经使用 Google 文档 ( https://developers.google.com/people/v1/getting-started ) 中给出的示例代码几乎逐字设置了 API 。我收到以下代码行的错误,它再次来自文档的逐字记录:
$profile = $people_service->people->get('people/me', array('personFields' => 'names,emailAddresses'));
Run Code Online (Sandbox Code Playgroud)
错误如下:
Fatal error: Uncaught exception 'Google_Exception' with message '(get) unknown parameter: 'personFields'' in /home/danbak15/bakerlegalservicesmo.com/office/google-api-php-client-2.2.0/src/Google/Service/Resource.php:147 Stack trace: #0 /home/danbak15/bakerlegalservicesmo.com/office/google-api-php-client-2.2.0/vendor/google/apiclient-services/src/Google/Service/People/Resource/People.php(52): Google_Service_Resource->call('get', Array, 'Google_Service_...') #1 /home/danbak15/bakerlegalservicesmo.com/office/BLScontacts.php(36): Google_Service_People_Resource_People->get('people/me', Array) #2 {main} thrown in /home/danbak15/bakerlegalservicesmo.com/office/google-api-php-client-2.2.0/src/Google/Service/Resource.php on line 147
Run Code Online (Sandbox Code Playgroud)
我看到了类似问题的答案(访问 google-people API 时无法访问我的个人资料数据)建议使用 Google_Service_PeopleService 类而不是文档中要求的 Google_Service_People 类。但是,当我尝试执行此操作时,出现另一个错误:
Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "code": 401, "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "errors": [ { "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "domain": "global", "reason": "unauthorized" } ], "status": "UNAUTHENTICATED" } } ' in /home/danbak15/bakerlegalservicesmo.com/office/google-api-php-client-2.2.0/src/Google/Http/REST.php:118 Stack trace: #0 /home/danbak15/bakerlegalservicesmo.com/office/google-api-php-client-2.2.0/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'G in /home/danbak15/bakerlegalservicesmo.com/office/google-api-php-client-2.2.0/src/Google/Http/REST.php on line 118
Run Code Online (Sandbox Code Playgroud)
在这一点上,我完全不知所措。我想使用 Google 通讯录来跟踪我的联系人,并希望能够通过 PHP 使用 Google 通讯录,以便我可以将它们添加到我的数据库中。任何人都可以对此有所了解吗?预先感谢您的任何帮助!
更新:我尝试将页面移动到我计算机上的本地服务器(忘记 Google 将页面重定向到我的网站),以查看是否可以从不同的服务器获得不同的结果。不知何故,神奇的是,当我尝试从我的网站访问脚本时,它起作用了——大约 15-30 分钟左右。然后,我得到了和以前一样的错误。如果我从我的本地主机服务器运行页面,我将陷入无休止的授权重定向循环(考虑到 Google 将我重定向到在线页面,这是意料之中的),但随后在线页面将工作一段时间。
在这一点上,我无法开始猜测问题出在哪里。这对其他人有意义吗?
我想我知道会发生什么。我的英语不是很好所以我希望你能明白我的意思..
就我而言,我使用 Google_Service_People 类 (src\Google\Service\People.php) 并得到与您相同的错误。所以我查看 People.php 并看到以下内容:
$this->people = new Google_Service_People_Resource_People(
$this,
$this->serviceName,
'people',
array(
'methods' => array(
'get' => array(
'path' => 'v1/{+resourceName}',
'httpMethod' => 'GET',
'parameters' => array(
'resourceName' => array(
'location' => 'path',
'type' => 'string',
'required' => true,
),
'requestMask.includeField' => array( // <= This is the problem.
'location' => 'query',
'type' => 'string',
),
),
),
Run Code Online (Sandbox Code Playgroud)
我查看了官方文档,上面写着“ requestMask.includeField 已被弃用。 ”但不知何故它仍然在 api 代码中。
所以我把它改成这样:
$this->people = new Google_Service_People_Resource_People(
$this,
$this->serviceName,
'people',
array(
'methods' => array(
'get' => array(
'path' => 'v1/{+resourceName}',
'httpMethod' => 'GET',
'parameters' => array(
'resourceName' => array(
'location' => 'path',
'type' => 'string',
'required' => true,
),
'personFields' => array( // <- Change to 'personFields'
'location' => 'query',
'type' => 'string',
),
),
Run Code Online (Sandbox Code Playgroud)
之后一切都很顺利。
如果您使用PHP 的 Google API 客户端库。该客户端库处于测试阶段。所以他们的 api 中的某些内容与 api 文档中的内容并不完全一样。
这就是我的情况。英语不是我的语言,所以我希望你能理解我试图描述的内容。
| 归档时间: |
|
| 查看次数: |
1515 次 |
| 最近记录: |