I'm using the Google APIs Client Library for PHP for offline authentication, but when I use this code:
$this->google->refreshToken($result["google_refresh_token"]));
it returns NULL.
$this->google
refers to an instance of the Google_Client class.
Anyone an idea what this could be?
If I try to change the given refresh token it returns a Google Exception Error, so it should be a valid token.
Thank you!
Edit:
'client_id' => 'myclientid',
'client_secret' => 'myclientsecret',
'redirect_uri' => 'mypage',
'developer_key' => 'mydeveloperkey',
// Other parameters.
'access_type' => 'offline',
'approval_prompt' => 'force',
Maybe this helps you
I was having this same issue for quite a while. For me it was because, for some reason, Google only sends you the refresh token the first time you request the token. So you have to make sure you store that refresh token for that user for all of entirety because Google wont give it to you again.
For development this can be a real pain. You can get Google to send you a new refresh token but what you have to do is deauthorize whatever account you authorized through your application. You can do this in your Google security settings.
Hope this helps!
I now use a really simple method to avoid the refresh_token()
method.
I just save the whole JSON response from the first request and give this to the setAccesToken()
method. If the access token expires, it will automatically get a new one from the given JSON.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With