So I've literally copied the code from the Google example (https://developers.google.com/google-apps/calendar/quickstart/php) and followed its instructions as best as I can, and then my calendar worked quite well. But I've come in today and realized that it stopped working, and I can't figure out what's wrong.
I believe the root of my problem is this line :
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
since that line gives me this error
Uncaught LogicException: refresh token must be passed in or set as part of setAccessToken
There are similar questions (Get refresh token google api, Not receiving Google OAuth refresh token) But I don't seem to be able to solve my problem with their answers.
Another note; $client->getRefreshToken()
seems to be returning null
when I test it, which is why I think $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
is failing.
So this is the piece of code directly from the example that is in question
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
file_put_contents($credentialsPath, json_encode($client->getAccessToken()));
}
That piece of code gives me errors because $client->getRefreshToken()
is null
, but I was under the assumption that I needed to use the refresh token to get a new token, which I can't do if there is no refresh token?
Also note, that this is already being set at the beginning of the calls
$client->setAccessType('offline');
$client->setApprovalPrompt('force');