Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user email from google plus oauth

Tags:

google-plus

Link: https://sites.google.com/site/oauthgoog/Home/emaildisplayscope

From the link above I add the email scope

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

But I dont understand the following

Once you have a valid OAuth token, you can use it to make API calls to the Email Display API endpoint: https://www.googleapis.com/userinfo/email If the token is not valid, a 401 error will be returned. If the token is valid, then the user's Email address will be returned. The API will also return a boolean value to indicate whether Google has verified that the user owns that Email address. However most installed applications will ignore that value.

How to make a call to the Email Display API endpoint? Using https://www.googleapis.com/userinfo/email

like image 412
Marian Petrov Avatar asked Jul 23 '12 03:07

Marian Petrov


2 Answers

Set your scopes to:

  • https://www.googleapis.com/auth/userinfo.email and
  • https://www.googleapis.com/auth/userinfo.profile

And use the endpoint:

https://www.googleapis.com/oauth2/v1/userinfo?alt=json

Usage:

get https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=youraccess_token 

You will get JSON:

{ "id": "xx",    "name": "xx",    "given_name": "xx",    "family_name": "xx",    "link": "xx",    "picture": "xx",    "gender": "xx",    "locale": "xx"  } 
like image 154
Joseph Rajeev Motha Avatar answered Oct 08 '22 20:10

Joseph Rajeev Motha


The scopes have changed for Google+ Sign-In.

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 profile information     console.log(resp);   }) }); 

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

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

like image 43
Chris Cartland Avatar answered Oct 08 '22 22:10

Chris Cartland