title: Invalid grant when accessing Google API
body: <p>I'm trying to invoke any of the Google API using "Service account" authorization access. I have downloaded ".pk2" file and activated "URL Shortener API" in Services tab of Google API console. Whenever I try to invoke any API (URL shortener or Adsense). I've got following exception - </p>
  
  <pre><code>com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
  {
    "error" : "invalid_grant"
  }
      at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
      at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:303)
      at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:323)
      at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:345)
      at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:526)
      at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:287)
      at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:836)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463)
  </code></pre>
  
  <p>Below is code snippet - </p>
  
  <pre><code>    HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
      JsonFactory JSON_FACTORY = new JacksonFactory();
      File privateKey = new File(ReportAdsense.class.getResource("mykey.p12").toURI());
      GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
              .setJsonFactory(JSON_FACTORY)
              .setServiceAccountId("my_valid_account_id@developer.gserviceaccount.com")
              .setServiceAccountScopes(UrlshortenerScopes.URLSHORTENER)
              .setServiceAccountPrivateKeyFromP12File(privateKey)
              .build();
       Urlshortener service = new Urlshortener.Builder(new NetHttpTransport(), JSON_FACTORY, null).setHttpRequestInitializer(credential).build();
       UrlHistory history = service.url().list().execute();
  </code></pre>