【发布时间】:2014-05-08 14:48:09
【问题描述】:
我需要用 Java 中的 Mendeley 创建一个应用程序。但是我对 oauth2 的连接有问题。
我使用 Apache Oltu,但如果您知道其他更好的选择,请告诉我。
我有这个:
OAuthClientRequest request = OAuthClientRequest
.tokenLocation("https://api-oauth2.mendeley.com/oauth/token")
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId(CLIENT_ID)
.setClientSecret(CLIENTE_SECRET)
.setRedirectURI(REDIRECT_URI)
.setCode("code")
.setScope("all")
.buildQueryMessage();
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
GitHubTokenResponse oAuthResponse = oAuthClient.accessToken(request, GitHubTokenResponse.class);
String accessToken = oAuthResponse.getAccessToken();
String expiresIn = oAuthResponse.getExpiresIn().toString();
System.out.println("ACCESS TOKEN: " + accessToken);
System.out.println("EXPIRES IN : " + expiresIn);
但这会产生这个异常:
Exception in thread "main" OAuthProblemException{error='invalid_request', description='Missing parameters: access_token', uri='null', state='null', scope='null', redirectUri='null', responseStatus=0, parameters={}}
at org.apache.oltu.oauth2.common.exception.OAuthProblemException.error(OAuthProblemException.java:59).......
有什么想法吗?我再说一遍,如果您知道其他替代方案或解决方案,请帮助我。
非常感谢。
【问题讨论】:
-
最后我做了正确的代码。我将
GitHubTokenResponse更改为:OAuthJSONAccessTokenResponse oAuthResponse = oAuthClient.accessToken(request,OAuthJSONAccessTokenResponse.class);所以,我拿走了access_token。
标签: java apache oauth oauth-2.0 mendeley