我需要用Java中的Mendeley创建一个应用程序。但是我在oauth2的conexion上遇到了问题。Oauth 2与Java的Mendeley
我使用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。 – angelo087