Get google account info using java's library gData

272 views
Skip to first unread message

alx

unread,
Mar 30, 2012, 4:41:39 AM3/30/12
to oauth...@googlegroups.com
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.

Robin Green

unread,
Mar 30, 2012, 4:54:57 AM3/30/12
to oauth...@googlegroups.com
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.

alx

unread,
Mar 30, 2012, 4:59:33 AM3/30/12
to oauth...@googlegroups.com
Thank you so much,

I'll just use the HTTP request and parse the JSON response.

Thanks again,
Alex.
Reply all
Reply to author
Forward
0 new messages