0

Mendeley の OAuth1 で問題なく動作するアプリケーションがありました。OAth1 はサポートされなくなったため、アプリを OAuth2 に移行してデータを取得する必要があります。

トークンの応答を受け取りましたが、コンテンツを要求できません。プログラムは NullPointerException をスローします。

このソースコードhereを使用してテストしています。

Apache OLTU と Apache HTTPClient も使用しています。

これは私が実行しようとするコードです:

static OAuthClientRequest request;
static OAuthClient oAuthClient;

static OAuthJSONAccessTokenResponse tokenResponse ;
static String CATALOG_URL="https://api-oauth2.mendeley.com/oapi/documents/groups?items=10";


request = OAuthClientRequest
            .tokenLocation("https://api-oauth2.mendeley.com/oauth/token")
            .setClientId(Client_ID)
            .setClientSecret(Secret)
            .setGrantType(GrantType.CLIENT_CREDENTIALS)
            .setScope("all")
            .buildBodyMessage();

System.out.println("is set up");

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

System.out.println("token is retrieved");

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

//this is where the Exception is thrown
       HttpResponse httpResponse =  apacheHttpClient.execute(httpGet);          
//

System.out.println("this is it: "+httpResponse.toString());

String responseAsString = EntityUtils.toString(httpResponse.getEntity());
System.out.println(responseAsString);

私が得る例外は次のとおりです。

Exception in thread "main" java.lang.NullPointerException

私は今、なぜこれが起こっているのか自問しています。CATALOG_URL は Mendeley Web サイドからのもので、すべての公開グループを含むリストの最初のページを返す必要があります。

Mendeley の Web サイトとは別の URL も試してみました。

HttpGet ステートメントに問題がある可能性はありますか?

誰にもヒントはありますか?

4

1 に答える 1