0

I'm making the same API calls as the below threads:

I know the code, service account e-mail and certificate works, because it works on one machine.

However, when I copy the code and certificate file to another machine, it fails with the TokenResponseExpection -invalid_grant.

I've checked time is in sync on both machines, and I've got the right certificate/code what else can I check to debug this?

Community
  • 1
  • 1
Igor Dvorkin
  • 827
  • 1
  • 8
  • 18
  • I have the same setup working on 2 machines, but failing on 1. Any ideas on how to debug would be most appreciated . – Igor Dvorkin Mar 23 '15 at 23:49

2 Answers2

0

Is the windows time of your machine right? Google API uses a timestamp for the authorisation token that can cause this error

Martijn
  • 45
  • 9
0

I think nobody knows why this is happening, I wasnt able to find any answer. I did my own investigation right here: TokenResponseException - Error:"invalid_grant", Description:"", Uri:"" and here: How to acquire a new Access token using Refresh token in Google OAuth 2.0 in .NET?

And it is still unknown why this is happening. I though it has something to do with access token expiration, but I am not sure, I wasn't able to figure out, AFAIU credentials token must aquire a new access token upon its expiration automatically when accessing Google API with a credentials token that contains expired access token and refresh token assigned (that was received the very first time and saved). And of course there is a limit of how many access tokens you can request - 25, or you ganna get "Invalid Grant: The refresh token limit has been exceeded (default is 25)."

The Token is an object that contains 2 other objects: AccessToken and RefreshToken. If RefreshToken is set to a value received upon authentication, then, if AccessToken expires after 1 hour, when you make a call to Google API, it should use the RefreshToken to acquire a new AccessToken. How exactly it does that - no idea, it should be internal hidden implementation of Google API.

Or I could be mistaken :)

Community
  • 1
  • 1
monstro
  • 6,254
  • 10
  • 65
  • 111