I'm trying to get a new access_token
after it has expired.
I already have in the database the information I get as a return on the client's first access:
{"access_token": "TOKEN", "refresh_token": "TOKEN", "token_type": "Bearer", "expires_in": 3600, "created": 1320790426}
After this token expires I need to request a new one, I'm doing this:
$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPES);
$client->setAuthConfigFile(CLIENT_SECRET_PATH);
$client->setAccessType('offline');
$token['access_token'] = $db->dados[0]['access_token'];
$token['refresh_token'] = $db->dados[0]['refresh_token'];
$token['token_type'] = $db->dados[0]['token_type'];
$token['expires_in'] = $db->dados[0]['expires_in'];
$token['created'] = $db->dados[0]['created'];
$client->setAccessToken(json_encode($token));
if ($client->isAccessTokenExpired()) {
echo "Expirado !";
$client->refreshToken($client->getRefreshToken());
} else {
echo "Valendo !";
}
The problem is that I always get this error message:
Error refreshing the OAuth2 token, message: '{"error": "invalid_grant"}