How can I get email address from Google Plus API once i got the token

余生长醉 提交于 2019-12-21 13:12:11

问题


I have got accesstoken using oauth2.0. I am able to get the person name, gender, etc but I am not able to get the email address of the user.

Could any one please paste some sample code or any suggestions on how to get the email address from the google plus API?


回答1:


You can retrieve a user's email address if they specifically authorize your application to see their email address.

Set your scopes to:

https://www.googleapis.com/auth/plus.login
https://www.googleapis.com/auth/userinfo.email

The JavaScript calls look like this:

gapi.client.load('oauth2', 'v2', function() {
  gapi.client.oauth2.userinfo.get().execute(function(resp) {
    // Shows user email
    console.log(resp.email);
  })
});

gapi.client.load('plus', 'v1', function() {
  gapi.client.plus.people.get( {'userId' : 'me'} ).execute(function(resp) {
    // Shows other profile information
    console.log(resp);
  })
});

More information https://developers.google.com/+.

Note that you do not need scopes for plus.me or userinfo.profile.




回答2:


Exposing E-mail addresses of people who have not set it to be visible to 'Public' would obviously be a privacy issue, so that's not possible.

Exposing E-mail addresses of people who have set their E-mail address visibility to 'Public' is possible, but not yet there. It is currently an open issue

Edit: The issue is resolved now, so you can follow the steps in the other answer to get it.



来源:https://stackoverflow.com/questions/10935628/how-can-i-get-email-address-from-google-plus-api-once-i-got-the-token

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