访问 google-人 API 时无法访问我的个人资料数据

Can't access my profile data when accessing google-people API

我想在我的项目中实施 Google Oauth2。我的主要目标是访问 google-people API 以显示个人资料信息,以及 google 驱动器。

因为我是新手,所以我激活了几个 API 并且 - 大多数时候 - 成功获取了信息。只有人 API 给我带来了问题,我不明白为什么。这是我正在做的(我跳过了所有登录部分)。

定义范围:

$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");

调用 APIs

$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 个有效。只有人员请求失败并且 returns 以下消息:

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

我不明白的部分是,此请求与我在文档中找到的示例完全相同 copy/past:https://developers.google.com/people/v1/read-people

有人知道为什么吗?

非常感谢!

看起来有两个服务 Google_Service_PeopleGoogle_Service_PeopleServiceGoogle_Service_People 似乎有旧的 API,而 Google_Service_PeopleService 是最新的。我会联系 PHP 库维护者找出为什么有两个库。