2017-08-03 146 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