I have a Java ClientRequest to the Google API that returns a json containing the profile based in an access_token. The URL is:
https://www.googleapis.com/oauth2/v1/userinfo?access_token=ya29.1.AADtN_VALuuUTBm8ENfNTz8s...
And the response is:
{ "id": "111223344556677889900", "email": "[email protected]", "verified_email": true, "name": "My Name", "given_name": "My", "family_name": "Name", "link": "plus.google.com/111223344556677889900", "picture": "photo.jpg", "gender": "male", "locale": "en" }
Some points:
1 I'd like to use the java library to avoid mount the http request, keep the google server url and another minor things.
2 I don't need the authorization's steps because at this point my method receives the access token (all the oauth steps are done before).
3 In this method we don't have (and so far don't need) the client id and secret.
4 I don't need the Google+ scope. Actually I prefer don't go there. So far only found examples using the Plus library.
In summary I need something in the google api java library exactly equivalent to the http request used nowadays.
Thank you very much in advance!
The client library provides a fluent API for common tasks and a JavaBeans compatible representation of the IBM® UrbanCode Release object model. The client library relies on the REST API. For more information about the supported operations, see REST API conventions.
After you have signed in a user with Google using the default scopes, you can access the user's Google ID, name, profile URL, and email address.
I hope this helps
GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
Oauth2 oauth2 = new Oauth2.Builder(new NetHttpTransport(), new JacksonFactory(), credential).setApplicationName(
"Oauth2").build();
Userinfoplus userinfo = oauth2.userinfo().get().execute();
userinfo.toPrettyString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With