这是我尝试从 github 接收访问令牌时出现的问题。
OAuthProblemException{error='unsupported_response_type', description='Invalid response! Response body is not application/json encoded', uri='null', state='null', scope='null', redirectUri='null', responseStatus=0, parameters={}}
我想让它尽可能通用,所以我不想使用这个GithubTokenResponse
类。我还有哪些选择可以避免异常?
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
OAuthClientRequest request = OAuthClientRequest
.tokenLocation("https://github.com/login/oauth/access_token")
.setCode(code)
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId(id)
.setClientSecret(secret)
.buildQueryMessage();
OAuthAccessTokenResponse tk = oAuthClient.accessToken(request); //this causes the problem
“丑陋”的解决方案:
GitHubTokenResponse tk = oAuthClient.accessToken(request, GitHubTokenResponse.class);