File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes [GoogleAPI] get user info Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "[GoogleAPI] get user info" Watch "[GoogleAPI] get user info" New topic

[GoogleAPI] get user info

kevin hack

Joined: Jun 20, 2011
Posts: 7
Hi all,

I need invocate google to get information account for my web site. I use OAuth 2.0 but I don't understand very well. I need help please.

I user 2 method:

Method 1... Step 1 and 2
Step 1
String next = "";
String scope = "";
boolean secure = false;
boolean session = true;
String authSubLogin = AuthSubUtil.getRequestUrl(next, scope, secure,

It's OK

Step 2
String token = request.getParameter("token");

I get token!!! but then how I can get user information? Where I use my
secret id and password?

Method 2... Step 1 and 2
String clientId = "xxxxxxxxxxx";
String callback = "http://" + request.getServerName() + ":" +
request.getServerPort() + request.getContextPath() + "/myUrl.jsp";
String authUrl = "
client_id=" + clientId + "&redirect_uri=" + callback + "&scope=https://";

STEP 2 (myUrl.jsp)
String code = request.getParameter("code");
String clientSecret = "yyyyyyyyyyyyyyyyyyyyy";
String newUrl = "";
String clientId = "xxxxxxxxxxxxxxxxxxxxxxxxx";
String callback = "http://" + request.getServerName() + ":" +
request.getServerPort() + request.getContextPath() + "/myUrl.jsp";
- mostra testo citato -
and then? How I can get User information?

Which is right version? Method 1 or 2?

Can you help me?


Thanks in advance
Roshan Dawrani

Joined: Aug 27, 2007
Posts: 2
I assume that you mean you want to fetch the user information for the current user (for whom you have acquired the access token from Google).

If yes, you can get that user's email address by making an authorized call (by passing the access token) from: (you will find code example if you search for it)

Retrieving other user info, like gender, full name, first/last name, etc is not supported by OAuth 2.0 api. Read here:

Markus Sprunck

Joined: Apr 11, 2012
Posts: 1
With the request "" + token; where token is a valid token form the user, you get the following information:
- family_name = Doe
- name = John Doe
- locale = en
- gender = male
- email =
- link = (link to Google+ profile)
- given_name = John
- id = 117292523089281814301
- verified_email = True
- picture = (url to Google+ profile picture)

I wrote a tutorial with a minimal in a GWT and Google AppEngine Java application ( This sample makes the OAuth2 stuff on the server. This means that you can use it as an API form your application.

Important steps are

A) Preparations to get a Web Applications Starter Project
- Create a web project in Eclipse with the name OAuthAppEngineSample (if you use the same name the next codes changes are easier to do).
- Now, create a new application on Google App Engine. This is necessary to deploy the application.
- Create a new application on Google App Engine Result (success)
- Deploy to AppEngine
- App Engine project settings
- Deploy to AppEngine
- Now you should have a version 1 in your AppEngine (check

B) Preparations for OAuth2 in Google APIs Console
- Create a client ID in the Google APIs Console (open and click on menu API Access)

C) Modify sample code

The tutorial is to long to post it here (lot screen shots and code), so just go to:

D) Further Reading
- Google AppEngine (Introduction);
- Using the Google Plugin for Eclipse:
- Google Dashboard (Authorized Access to your Google Account);
- Using OAuth 2.0 to Access Google APIs;
- Google AppEngine (Sign up);
- Google APIs;

I hope this helps

Marco Bernardini

Joined: Aug 28, 2012
Posts: 1
Hi Markus,
I followed your tutorial and works great!
Apparently the library you're using( doesn't provide the feature to refresh the token.
So, after the token expiration(1h), you need to re-allow the application. This is very annoying...
Did you find any "workaround" on this issue?

Thanks in advance
I agree. Here's the link:
subject: [GoogleAPI] get user info
jQuery in Action, 3rd edition