I\'ve nearly searched every result of the first page of google for this. But can\'t seem to find the answer. I\'m working with a refresh_token by Google\'s API and receiving
The function that worked for me is as follows
$client->setAccessType("refresh_token");
I ran into something similar and the problem for me was my system clock (inside the Docker VM where I was running the code) was not synchronized with the real time. So you are requesting a token with a created date too far in the past or future, which OAuth is rejecting.
I was tipped of by the report here.
You'll get an "invalid_grant" error if you try to refresh when the token isn't expired.
Instead of this:
$client->refreshToken(file_get_contents('../_config/refreshtoken.conf'));
Use this:
$client->setAccessToken(file_get_contents('../_config/refreshtoken.conf'));
Once your token expires you refresh should work.
The invalid_grant means either means that the authorization code has already been used (available in $GET['code']
) or the type of application configured in the Google APIs Console is invalid.
Make sure you select "Web Application" when registering your app in the Google APIs Console.
Before Authenticate, there must be something like:
$client->grantType("refresh_token")