我試圖在Web應用程序中交換一個令牌接收到的授權碼,但當我調用GoogleAuthorizationCodeTokenRequest時,出現此錯誤: 「無效的redirect_uri參數值: 無效的計劃:https://mapmydayunamur.appspot.com/getauthcodeservlet「Oauth 2.0交換授權碼令牌:無效的重定向方案uri
我試過很多redirect_uri,不知道爲什麼我得到這個錯誤。 Uri在我的開發者控制檯中重定向Uri。 這裏是我的代碼: 在getauthcodeservlet.java:
String authcode = req.getParameter("code");
String clientID = "CLIENTID_FROM_GOOGLEDEVELOPERSCONSOLE"
String clientSecret = "CLIENTSECRET_FROM_GOOGLEDEVELOPERSCONSOLE";
String redirectUri = "https://mapmydayunamur.appspot.com/getauthcodeservlet";
try {
GoogleTokenResponse response =
new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(),clientID, clientSecret, authcode,redirectUri).execute();
resp.getWriter().println("Access token: " + response.getAccessToken());
} catch (TokenResponseException e) {
if (e.getDetails() != null) {
resp.getWriter().println("Error: " + e.getDetails().getError());
if (e.getDetails().getErrorDescription() != null) {
resp.getWriter().println(e.getDetails().getErrorDescription());
}
if (e.getDetails().getErrorUri() != null) {
resp.getWriter().println(e.getDetails().getErrorUri());
}
} else {
resp.getWriter().println(e.getMessage());
}
}
}
謝謝你幫我
空格字符在HTTPS的面前? 「HTTPS ... – pinoyyid 2014-11-04 16:56:11
對不起時複製粘貼我的代碼進入論壇。 現在,它的良好的版本,不適合你的答案既不工作.. 還是要謝謝你! – 2014-11-04 17:54:15