我正在使用google oauth Java客户端使用授权代码获取访问令牌。我收到上述错误,不确定是什么问题。这是我正在使用的代码
TokenResponse response = new AuthorizationCodeTokenRequest(
new NetHttpTransport(), new JacksonFactory(),
new GenericUrl(TOKEN_END_POINT), authorizationCode
)
.setRedirectUri(REDIRECT_URI)
.setClientAuthentication(new ClientParametersAuthentication(CLIENT_ID, CLIENT_SECRET))
.execute();
答案 0 :(得分:0)
经过很多努力,我终于找到了答案。找到答案几乎花了1天的时间。这是解决方案。
final String encString = Base64.getEncoder().encodeToString((clientId+":"+clientSecret).getBytes());
TokenResponse response = new AuthorizationCodeTokenRequest(
new NetHttpTransport(), new JacksonFactory(),
new GenericUrl(TOKEN_ENDPOINT), authorizationCode
)
.setRequestInitializer(new HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException {
request.getHeaders().setAuthorization("Basic "+encString);
}
})
.setRedirectUri(REDIRECT_URI)
.execute();