Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a google's email/username in java?

is it possible to retrieve the username of a google account that i have succesfully authenticated using OAuth?

i have retrieved the users Access tokens but i am wondering if their is a API call i can make such has https://google.api/getUserName and pass the access tokens to that call and succesfully retrieve the users email/username?

In a normal OAuth web service, all you need is the secret and id access tokens to make calls to the web service but in google you also need the username too.

Any ideas?

like image 820
Jonathan Avatar asked Nov 17 '10 11:11

Jonathan


3 Answers

Take a look at http://sites.google.com/site/oauthgoog/Home/emaildisplayscope . That should work for you.

like image 150
gk5885 Avatar answered Oct 31 '22 17:10

gk5885


The only way I figured so far is using the Spreadsheet API.

If you request the feed, that lists all documents

https://spreadsheets.google.com/feeds/spreadsheets/private/full?alt=json

There is a field with the username as well:

response.data.feed.title.$t

Unfortunately, this means prompting the user to grant access to his GDocs account, which may be confusing..

But I don't know of any API by Google to directly get the username.

like image 39
JochenJung Avatar answered Oct 31 '22 18:10

JochenJung


Best way, the following feed was retrieved from the Contacts Data API:

https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=0

and get next fields from the feed:

response.data.feed.id

or

response.data.feed.author.name.$t
response.data.feed.author.email.$t
like image 45
Pavlo Bashynskyi Avatar answered Oct 31 '22 16:10

Pavlo Bashynskyi