Skip to content

Instantly share code, notes, and snippets.

@hitenpratap
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitenpratap/b0af2135d26bfdb56c2d to your computer and use it in GitHub Desktop.
Save hitenpratap/b0af2135d26bfdb56c2d to your computer and use it in GitHub Desktop.
Google+ Example for Scribe
private static final String SCOPE = "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.stream.read " +
"https://www.googleapis.com/auth/plus.stream.write";
// TO Connect TO Google
String appId = "your Google app client key"
String appSecret = "your Google app client secret"
String callbackurl = "callback url (must registered with google)"
OAuthService service = new ServiceBuilder()
.provider(Google2Api.class) //get provider class from https://gist.github.com/hitenpratap/ac7d306bc5eff1ef0549
.apiKey(appId)
.apiSecret(appSecret)
.callback(callbackurl)
.scope(SCOPE)
.build();
//redirect your user to following url
String redirectURL = service.getAuthorizationUrl(null);
//Now user should authorize the app and then he would be redirected to callback url with code
Token token = service.getAccessToken(null, new Verifier(req.getParameter('code')));
//Now you can get access token using following code
String accessToken = token.token;
//TO fetch user's basic info from Gogole use following code snippet
String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json";
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(token, request);
Response response = request.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment