How to get email address along with people list in

2019-07-02 02:51发布

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?

2条回答
虎瘦雄心在
2楼-- · 2019-07-02 03:06

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

查看更多
看我几分像从前
3楼-- · 2019-07-02 03:14

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.

查看更多
登录 后发表回答