2
我正在使用谷歌啓動項目的代碼到我的一個gaelyk應用程序。這是OAuth 2.0授權流程的Groovy編碼。與twitter不同,只要應用程序要求授權,用戶必須允許該應用程序繼續,我認爲這很奇怪。我犯了一些錯誤?OAuth和谷歌加API a
// Check for an error returned by OAuth
if (params.error) {
response.setContentType("text/plain");
out.println("There was a problem during authentication: " + error);
log.severe("There was a problem during authentication: " + error);
return;
}
// When we're redirected back from the OAuth 2.0 grant page, a code will be supplied in a GET parameter named 'code'
if (!params.code) {
// Now that we have the OAuth 2.0 code, we must exchange it for a token to make API requests.
// Build the authorization URL
AuthorizationRequestUrl authorizeUrl = new GoogleAuthorizationRequestUrl(
CLIENT_ID,
REDIRECT_URI,
SCOPES
);
authorizeUrl.redirectUri = REDIRECT_URI;
authorizeUrl.scope = SCOPES;
String authorizationUrl = authorizeUrl.build();
log.info("Redirecting browser for OAuth 2.0 authorization to " + authorizationUrl);
response.sendRedirect(authorizationUrl);
return;
} else {
log.info("Exchanging OAuth code for access token using server side call");
AccessTokenResponse accessTokenResponse = new GoogleAccessTokenRequest.GoogleAuthorizationCodeGrant(
new NetHttpTransport(),
new GsonFactory(),
CLIENT_ID,
CLIENT_SECRET,
params.code,
REDIRECT_URI
).execute();
log.info("Storing authentication token into the session");
request.session.accessToken = accessTokenResponse.accessToken
request.session.refreshToken = accessTokenResponse.refreshToken
//The authentication is all done! Redirect back to the samples index so you can play with them.
response.sendRedirect("/");
}
redirect_uri的值是多少?我在這裏遇到問題。 –