Last active
August 29, 2015 14:07
-
-
Save hitenpratap/b0af2135d26bfdb56c2d to your computer and use it in GitHub Desktop.
Google+ Example for Scribe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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