Can't access my profile data when accessing go

2019-06-04 19:52发布

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.

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).

Defining the scopes:

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

Calling the 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);

Making requests

$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

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

Anybody understands why?

Thanks a lot!

1条回答
不美不萌又怎样
2楼-- · 2019-06-04 20:29

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.

查看更多
登录 后发表回答