1

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).......

何か案が?繰り返しますが、別の代替手段または解決策を知っている場合は、助けてください。

どうもありがとう。

4

1 に答える 1

1

http://apidocs.mendeley.com/home/authenticationの Web サイトにいくつかのドキュメントがあります。

Apache Oltu ライブラリと Apache HTTP クライアント ライブラリを使用した、より完全な例をまとめました。これは、匿名アクセス トークンを使用します。

編集

OAuthClientRequest request = OAuthClientRequest
            .tokenLocation(TOKEN_URL)
            .setClientId(TRUSTED_CLIENT_ID)
            .setClientSecret(TRUSTED_SECRET)
            .setGrantType(GrantType.CLIENT_CREDENTIALS)
            .setScope("all")
            .buildBodyMessage();

    OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
    OAuthJSONAccessTokenResponse tokenResponse = oAuthClient.accessToken(
            request, OAuthJSONAccessTokenResponse.class);

    HttpGet httpGet = new HttpGet(CATALOG_URL);
    httpGet.setHeader("Authorization", "Bearer " + tokenResponse.getAccessToken());
    HttpResponse httpResponse = apacheHttpClient.execute(httpGet);

    assertThat(httpResponse.getStatusLine().getStatusCode()).isEqualTo(200);

    String responseAsString = EntityUtils.toString(httpResponse.getEntity());

    ObjectMapper mapper = new ObjectMapper();
    Document document = mapper.readValue(responseAsString, Document.class);
    assertThat(document.getTitle()).isEqualTo("Identifying and recording user actions to enable automatic online assessment");
于 2014-05-09T11:27:29.910 に答える