Google Groups

Re: Get google account info using java's library gData


Robin Green Mar 30, 2012 1:54 AM
Posted in group: Developer Forum for Google API Access using OAuth2
You don't need to use the Contacts API for this - you can just use the UserInfo service (which is better because then you are just asking the user for permission to access the information you need). However, if you use that, it doesn't matter whether you use gdata or the newer API, there is no Java API for the UserInfo service. You need to parse the info yourself, using the documentation at

https://developers.google.com/accounts/docs/OAuth2Login#userinfocall

Fortunately that's quite easy - just make a HTTP request and use Jackson to parse the returned JSON.

On Friday, 30 March 2012 09:41:39 UTC+1, alx wrote:
Hi,

Does anybody knows how to get user info(first name, last name, full name, email) from an google account using gData?
I must mention that I am able to perform the auth(I get the auth token from an android device - sent it to my server - auth using gData), but I don't know what Classes/calls to perform further in order to get the user info of the account.

Here is what I did:
ContactsService contactsService = new ContactsService("...");
contactsService.setUserToken(auth_token);   
ContactFeed feed = null;
try {  
  feed = contactsService.getFeed(new URL("https://www.google.com/m8/feeds/contacts/" + "some...@gmail.com" + "/full?max-results=10000"), ContactFeed.class);
}
catch (IOException e) {
  e.printStackTrace();
  return CONST.GOOGLE_AUTH_INVALID_TOKEN;
}
catch (ServiceException e) {
  e.printStackTrace();
  return CONST.GOOGLE_AUTH_INVALID_TOKEN;
}  
catch (NullPointerException e) {
  e.printStackTrace();
  return CONST.GOOGLE_AUTH_INVALID_TOKEN;
}

Thanks,
Alex.