使用此代码将来自 Drive UI 的请求的初始代码与我可以用来发出 API 请求的令牌交换。
public GoogleCredential exchangeCode(String authorizationCode) throws CodeExchangeException {
try {
GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(), CLIENT_ID, CLIENT_SECRET, authorizationCode, REDIRECT_URI).execute();
return new GoogleCredential.Builder().setClientSecrets(CLIENT_ID, CLIENT_SECRET).setTransport(new NetHttpTransport()).setJsonFactory(new JacksonFactory()).build().setFromTokenResponse(response);
}
catch (Exception e) {
log.error("An error occurred: " + e);
throw new CodeExchangeException(null);
}
}
在大多数情况下它有效,但在某些情况下(可能是 5%),我得到
An error occurred: com.google.api.client.auth.oauth2.TokenResponseException: 500 Error processing OAuth 2 request
<HTML>
<HEAD>
<TITLE>Error processing OAuth 2 request</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Error processing OAuth 2 request</H1>
<H2>Error 500</H2>
</BODY>
</HTML>
可能是什么问题呢?