I have successfully created an application that retrieves the access token and updates.
In my script, I check if the access token is valid, and if not, I use the update token to access $client->refreshToken($refreshToken);
Full code
$refreshToken = '<REFRESH_TOKEN>'; $client_id = '<CLIENT_ID>'; $client_secret = '<CLIENT_SECRET>'; // Setup infomation $client = new Google_Client(); $client->setClientId($client_id); $client->setClientSecret($client_secret); $client->setAccessType("offline"); $client->addScope("https://mail.google.com/"); // If access token is not valid use refresh token if($client->isAccessTokenExpired()) { // Use refresh token $client->refreshToken($refreshToken); } else { // Use access token echo $client->setAccessToken($accessToken); }
However, when I try to use the update token, I get excpetion:
Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }''
token gmail-api
Jack trowbridge
source share