受信した認証コードを Web アプリケーションのトークンと交換しようとしていますが、GoogleAuthorizationCodeTokenRequest を呼び出すと、次のエラーが表示されます。
多くの 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());
}
}
}
私を助けてくれてありがとう