访问google-people API时无法访问我的个人资料数据 [英] Can't access my profile data when accessing google-people API

查看:305
本文介绍了访问google-people API时无法访问我的个人资料数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的项目中实现Google Oauth2.我的主要目标是访问google-people API以显示个人资料信息和google drive.

I want to implement Google Oauth2 on my project. My main goals are accessing the google-people API in order to display profile information, and google drive.

因为这是我的新手,所以我激活了多个API,并且-在大多数情况下-成功获取了信息.只有People API引起了我的麻烦,我不明白为什么.这就是我正在做的事情(我将跳过所有登录部分).

Because I'm new with this, I activated several APIs and -most of the times- succeeded in getting info. Only the People API is causing me problems, and I don't get why. Here is what I'm doing (I'm skipping all the login part).

定义范围:

$client->addScope("https://www.googleapis.com/auth/drive");
$client->addScope("https://www.googleapis.com/auth/youtube");
$client->addScope("https://www.googleapis.com/auth/contacts"); // this is google-people API
$client->addScope("https://www.googleapis.com/auth/plus.login");
$client->addScope("https://www.googleapis.com/auth/userinfo.email");
$client->addScope("https://www.googleapis.com/auth/gmail.readonly");

调用API

$dr_service = new Google_Service_Drive($client);
$yt_service = new Google_Service_YouTube($client);
$ppl_service = new Google_Service_People($client);
$plus_service = new Google_Service_Plus($client);
$gmail_service = new Google_Service_gmail($client);

提出请求

$dr_results = $dr_service->files->listFiles(array('pageSize' => 10)); //returns a list of files
$yt_response= $yt_service->search->listSearch('id,snippet', array('maxResults' => 25, 'q' => 'yoda', 'type' => '') );//returns videos of Yoda
$plus_results = $plus_service->people->get('me'); // returns my Google+ profile
$gmail_results = $gmail_service->users->getProfile('me'); //returns my Gmail profile
$ppl_results = $ppl_service->people->get( 'people/me', array('personFields' => 'names,emailAddresses') ); //Error

如您所见,5个请求中有4个正在运行.仅人员"请求失败,并返回以下消息:

As you can see, 4 out of 5 requests are working. Only the People request is failing and returns the following message:

Fatal error: Uncaught Google_Exception: (get) unknown parameter: 'personFields' in C:\xampp\htdocs\gLoginPHP\vendor\google\apiclient\src\Google\Service\Resource.php:147 Stack trace: #0 C:\xampp\htdocs\gLoginPHP\vendor\google\apiclient-services\src\Google\Service\People\Resource\People.php(52): Google_Service_Resource->call('get', Array, 'Google_Service_...') #1 C:\xampp\htdocs\gLoginPHP\gLoginPHP.php(81): Google_Service_People_Resource_People->get('people/me', Array) #2 {main} thrown in C:\xampp\htdocs\gLoginPHP\vendor\google\apiclient\src\Google\Service\Resource.php on line 147

我不了解的部分是,此请求是我在文档中找到的示例的准确副本/过去:

The part that I don't understand, is that this request is an exact copy/past from an example I found in the documentation: https://developers.google.com/people/v1/read-people

有人知道为什么吗?

非常感谢!

推荐答案

似乎有两个服务Google_Service_PeopleGoogle_Service_PeopleService. Google_Service_People似乎具有较旧的API,而Google_Service_PeopleService是最新的.我将联系PHP库维护者以弄清楚为什么有两个库.

It looks like there are two services Google_Service_People and Google_Service_PeopleService. Google_Service_People seems to have the older API, whereas Google_Service_PeopleService is up to date. I will contact the PHP library maintainers to figure out why there are two libraries.

这篇关于访问google-people API时无法访问我的个人资料数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆