How can I get the email address from the Google Plus API as soon as I received the token

I have accesstoken using oauth2.0. I can get the name, gender, etc., but I can not get the email address of the user.

Can I insert some sample code or any suggestions on how to get the email address from the Google+ API?

+6
source share
2 answers

You can get the user's email address if they specifically allow your application to see their email address.

Define your scope:

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

JavaScript calls are as follows:

 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); }) }); 

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

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

+9
source

Revealing the email addresses of people who haven’t made it public will obviously be a privacy issue, so this is not possible.

The impact of the email addresses of people who set the email address visibility to "General" is possible, but does not yet exist. Currently open issue

Edit: The problem is fixed now, so you can follow the steps in another answer to get it.

+1
source

Source: https://habr.com/ru/post/917540/


All Articles