我试图在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