title: Google Analytics : Get access token from refresh token
body: <p>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.</p>
  
  <p>After password change, our request token became invalid. So, I generated a new refreshtoken by browsing the url (<a href="https://developers.google.com/oauthplayground" rel="nofollow">https://developers.google.com/oauthplayground</a>) 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:</p>
  
  <pre><code>RefreshTokenRequest request = new GoogleRefreshTokenRequest(HTTP_TRANSPORT, JSON_FACTORY, refreshToken,
                      this.clientId, this.clientSecret);
              TokenResponse response = request.execute(); 
  </code></pre>
  
  <p>When execute method is invoked, it throws the following exception:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Can anyone please point where am I doing wrong? I am able to get the access token from google oAuth UI.</p>