2017-08-03 59 views
1

我想在我的项目中实施Google Oauth2。我的主要目标是访问谷歌人API以显示个人资料信息和谷歌驱动器。访问google-people时无法访问我的个人资料数据API

因为我是新来的,所以我激活了几个API,大部分时间都成功地获取了信息。只有People 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"); 

调用的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 

正如你看到的,4,满分5请求工作。只有人民的请求失败,并返回以下消息:

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 

,我不明白的一部分,该请求是从一个例子,我的文档中找到精确的复制/过去:https://developers.google.com/people/v1/read-people

任何人都明白为什么?

非常感谢!

回答

0

看起来有两种服务Google_Service_PeopleGoogle_Service_PeopleServiceGoogle_Service_People似乎具有较旧的API,而Google_Service_PeopleService是最新的。我会联系PHP库维护人员,弄清为什么有两个库。

+0

的确我没有看到这个Google_Service_PeopleService。当我使用这个代码时,我的代码完美工作。 感谢您的帮助! 听听你可以从图书馆维护人员那里学到什么是非常有趣的。 – Yann