4

I am working with google analytics api in Java. I have a code which fetches access token from refresh token. We store the refresh token in the database and while requesting, retrieve access token.

After password change, our request token became invalid. So, I generated a new refreshtoken by browsing the url (https://developers.google.com/oauthplayground) and following the instructions. I got the new refresh token. Now, when I am executing the code to retrieve access token, it throws null pointer exception. Following is the code:

RefreshTokenRequest request = new GoogleRefreshTokenRequest(HTTP_TRANSPORT, JSON_FACTORY, refreshToken,
                    this.clientId, this.clientSecret);
            TokenResponse response = request.execute(); 

When execute method is invoked, it throws the following exception:

java.lang.NullPointerException
    at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull(Preconditions.java:191)
    at com.google.api.client.util.Preconditions.checkNotNull(Preconditions.java:127)
    at com.google.api.client.json.jackson2.JacksonFactory.createJsonParser(JacksonFactory.java:96)
    at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:85)
    at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
    at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:88)
    at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
    at com.google.api.client.googleapis.auth.oauth2.GoogleRefreshTokenRequest.execute(GoogleRefreshTokenRequest.java:125)
    at com.google.api.client.googleapis.auth.oauth2.GoogleRefreshTokenRequest.execute(GoogleRefreshTokenRequest.java:75)
    at GARTest.main(GARTest.java:22)

Can anyone please point where am I doing wrong? I am able to get the access token from google oAuth UI.

4

1 回答 1

2

这可能有你的答案:https ://github.com/googleads/googleads-java-lib/issues/19

Github 用户 jyothi462 说他的 NPE最终是由于使用了错误的 client id 和 secret 造成的。这也是我的问题。

该问题已通过更新错误消息得到解决,使其更具描述性。

于 2014-12-03T21:48:42.917 回答