Reputation: 71
I am using Gooogledrive Api with php.Using it I have retrieved Refresh token from credentials part.The accesstoken expires after 3600 seconds.My question is how to get the new accesstoken from this refresh token.I have used the method given in Google php client library.I have called the refreshtoken('refreshtoke') function of apiclient.My code is following
$client = new apiClient();
$client->setClientId('my-client-id');
$client->setClientSecret('my client-secret-key');
$client->setRedirectUri('my redirect uri');
$client->refreshToken('MY-retrieved-refresh-token');
But I get the following error:- Uncaught exception 'apiAuthException' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }.**
Please help me .Everything rest works fine.But accesstoken expires after 3600 seconds and is not refreshing
Upvotes: 2
Views: 658
Reputation: 1092
//after this line of code
$client->refreshToken('MY-retrieved-refresh-token');
//do this
$token = $client->getAccessToken();
// this will give you json encode string which will have access, refresh token and bearer etc.
Upvotes: 1