我想在我的项目中实施 Google Oauth2。我的主要目标是访问 google-people API 以显示个人资料信息和 google drive。
因为我是新手,所以我激活了几个 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
如您所见,5 个请求中有 4 个正在工作。只有 People 请求失败并返回以下消息:
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
有人明白为什么吗?
非常感谢!