I'm using the Gmail API for reads emails and just add/remove labels.
I authenticated correctly, I get my access token with 3600 seconds of life.
And here starts the problems... When I try to Refresh Token, I got a null, so I can't refresh it.
Some code:
$this->client = new Client();
$this->client->setApplicationName('App');
$this->client->setClientId('xxxxxxx');
$this->client->setClientSecret('xxxxxxx');
$this->client->setRedirectUri('xxxxxxx/oauth/gmail/callback');
$this->client->setScopes([GoogleGmail::GMAIL_READONLY, GoogleGmail::GMAIL_MODIFY]);
$this->client->setPrompt('select_account consent');
$this->client->setAccessType('offline');
In the callback I do:
$this->client->fetchAccessTokenWithAuthCode($code);
Output:
{
"access_token":"xxxxxxxxxx",
"expires_in":3599,
"scope":"https:\/\/www.googleapis.com\/auth\/gmail.readonly https:\/\/www.googleapis.com\/auth\/gmail.modify",
"token_type":"Bearer",
"created":7374384324
}
I saved the Access Token, Expired time, and all data really. But I don't get the refresh token.
I try with:
$this->client->getRefreshToken(); // null
And If I do
$this->client->isAccessTokenExpired()
I always get true
, inclusive if I auth 5 seconds ago.
I'm using google/apiclient v2.15.0
, PHP 8.1
Thanks