How to get email address along with people list in google plus API

戏子无情 提交于 2020-01-04 04:07:07

问题


I'm using google plus API in my web app. I could pull out all people from google plus

My code is

$this->client = new Google_Client();
        $this->client->setApplicationName($CI->config->item('application_name', 'googleplus'));
        $this->client->setClientId($CI->config->item('client_id', 'googleplus'));
        $this->client->setClientSecret($CI->config->item('client_secret', 'googleplus'));
        $this->client->setRedirectUri($CI->config->item('redirect_uri', 'googleplus'));
        $this->client->setDeveloperKey($CI->config->item('api_key', 'googleplus'));

        $this->plus = new Google_PlusService($this->client);
              $this->auth2 = new Google_Oauth2Service($this->client);

$peoples = $this->plus->people->listPeople('me','visible');

Here I'm getting list of all the peoples in my circle. But I dont get people's email address and birthdays. How can I get those too?


回答1:


Once you have a list of Google+ IDs, you will need to make a people.get call to gain the [public] profile data for those users. In PHP, this call looks like $me = $plus->people->get('me');. For an authorized user, the 'me' keyword can be used. Otherwise, you can make the call using a Google+ ID.

Once you have made that call, you can pull out the attributes that are relevant to you (full list: https://developers.google.com/+/api/latest/people).

However, to get the Google email address for a user, you will need to include the https://www.googleapis.com/auth/userinfo.email scope in addition to the plus.login scope. This means that you may only get the email addresses of authorized users.




回答2:


Please read the document on Google+ OAuth 2.0 scopes which explains that you need to use the scope https://www.googleapis.com/auth/userinfo.email and then send your access token to the tokenInfo endpoint to get the user's email address as a part of the validation information



来源:https://stackoverflow.com/questions/17672709/how-to-get-email-address-along-with-people-list-in-google-plus-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!