Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the oauth authorization with google working correctly and am getting data from the contacts api. Now, I want to programmatically get a gmail user's first name, last name and picture. Which google api can i use to get this data?

share|improve this question
2  
No one has any clue about this? I was surprised myself when I didn't find any simple answer on google's website... – Pranav Jan 21 '10 at 14:35
Is oauth the same as openid? – anon Jan 22 '10 at 3:53
Are you trying to get the name and picture for the contacts or for the user you authenticated? – Mark Koberlein Jan 22 '10 at 4:17
For the user. Getting contacts info wont be difficult as there is an api for it. – Pranav Jan 22 '10 at 5:17
@Pranav currently i am working in this! can you please share the code which have you done will be helpful for me to proceed – GowthamanSS Mar 13 at 14:18

4 Answers

up vote 3 down vote accepted

I found the answer while looking around in the contacts API forum. When you get the result-feed, just do the following in Java-

String Name = resultFeed.getAuthors().get(0).getName();

String emailId = resultFeed.getId();

Im still looking for a way to get the picture.

share|improve this answer
   
can you post some code sample for getting first name, last name, email from google. The url you are requesting. I am doing same in android app. Thanks in Advance. – Panache Aug 31 '11 at 7:21
What has Java got to do with the Google APIs? – Chris Harrison Mar 22 at 6:11

The contacts API perhaps works, but you have to request permission from the user to access all contacts. If I were a user, that would make me wary of granting the permission (because this essentially gives you permission to spam all my contacts...)

I found the response here to be useful, and only asks for "basic profile information":

Get user info via Google API

I have successfully used this approach, and can confirm it returns the following Json object:

{
  "id": "..."
  "email": "...",
  "verified_email": true,
  "name": "....",
  "given_name": "...",
  "family_name": "...",
  "link": "...",
  "picture": "...",
  "gender": "male",
  "locale": "en"
}
share|improve this answer
+1 for this answer as it actually addresses the Google APIs that the question asked, as opposed to the current accepted answer which is just some random Java code. – Chris Harrison Mar 22 at 6:09

For the picture, you can use the Google contacts Data API too: see http://code.google.com/intl/fr/apis/contacts/docs/3.0/developers_guide_protocol.html#retrieving_photo

share|improve this answer
but how do you retrieve the photo for the logged in user? I tried google.com/m8/feeds/photos/media/default/…... but I get the error "Photo query failed - invalid contact ID". – Felipe Brahm Aug 10 '11 at 23:17
In your URL, just URLencode the email address (write %40 instead of @) and it should work... – olivierlemasle Aug 11 '11 at 20:54
I've just discovered a new Google API that you can use: Portable Contacts API (code.google.com/intl/fr-FR/apis/contacts/docs/poco/1.0/…) It's easier to retrieve the user photo: you authenticate with the scope www-opensocial.googleusercontent.com/api/people, you get user info with request www-opensocial.googleusercontent.com/api/people/@me/@self and it contains the URL of the photo... – olivierlemasle Aug 11 '11 at 20:57
are you sure urlencoding the email should work? I just tried it and I keep getting the same error message. What I did to go around this was to use the Google Social API (www-opensocial.googleusercontent.com/api/people/@me/@self) to get the user info. The only problem is that that url can only be called on the server-side because you need to set a custom OAuth authorization header. – Felipe Brahm Aug 11 '11 at 22:35
This url www-opensocial.googleusercontent.com/api/people/@me/@self isn't working now. Any idea on this ? – Sanket Jan 25 at 8:44
show 1 more comment

The simplest way to get this information would be from the Google + API. Specifically the

https://developers.google.com/+/api/latest/people/get

When using the api use the following HTTP GET:

GET https://www.googleapis.com/plus/v1/people/me

This will return all of the above information requested from the user.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.