Google API Client "refresh token must be passed in or set as part of setAccessToken" : <p>I am currently facing a very strange problem, indeed I've been following this very same guide (<a href="https://developers.google.com/google-apps/calendar/quickstart/php" rel="noreferrer">https://developers.google.com/google-apps/calendar/quickstart/php</a>) from Google API documentation. I tried it twice, at the first time it work like a charm but after the access token had expire the script provided straight by Google API Doc was unable to refresh it.</p>

<p>TL;DR</p>

<p>Here is the error message:</p>

<pre><code>sam@ssh:~$ php www/path/to/app/public/quickstart.php


Fatal error: Uncaught exception 'LogicException' with message 'refresh token must be passed in or set as part of setAccessToken' in /home/pueblo/www/path/to/app/vendor/google/apiclient/src/Google/Client.php:258
Stack trace:
#0 /home/pueblo/www/path/to/app/public/quickstart.php(55): Google_Client-&gt;fetchAccessTokenWithRefreshToken(NULL)
#1 /home/pueblo/www/path/to/app/public/quickstart.php(76): getClient()
#2 {main}
  thrown in /home/pueblo/www/path/to/app/vendor/google/apiclient/src/Google/Client.php on line 258
</code></pre>

<p>Here is the part of the php script from google I've modified:</p>

<pre><code>require_once __DIR__ . '/../vendor/autoload.php';

// I don't want the creds to be in my home folder, I prefer them in the app's root
define('APPLICATION_NAME', 'LRS API Calendar');
define('CREDENTIALS_PATH', __DIR__ . '/../.credentials/calendar-php-quickstart.json');
define('CLIENT_SECRET_PATH', __DIR__ . '/../client_secret.json');
</code></pre>

<p>I also modified the <code>expandHomeDirectory</code> so I could "disable" it without modifying too much code:</p>

<pre><code>function expandHomeDirectory($path) {
  $homeDirectory = getenv('HOME');
  if (empty($homeDirectory)) {
    $homeDirectory = getenv('HOMEDRIVE') . getenv('HOMEPATH');
  }
  return $path;
  // return str_replace('~', realpath($homeDirectory), $path);
}
</code></pre>

<p>So to check if I was wrong or if Google was, I did an experiment: yesterday night I launch the quickstart script from ssh to check if it was working, and indeed it was, so I decided to check this morning if it still working just as it was before I slept and it wasn't so I think there's something wrong with Google's <code>quickstart.php</code>.</p>

<p>I hope someone could help me, I already checked all the other posts about the subject but they are all outdated.</p>
