0

I am using Google Sheet API V4.

I follows these instructions for accessing my sheet. It works well well on first day. Then second day i run again following command to run the script.

php quickstart.php

When i runs the above command it shows me following error

PHP Fatal error: Uncaught LogicException: refresh token must be passed in or se t as part of setAccessToken in C:\xampp\htdocs\sheetapi\vendor\google\apiclient\ src\Google\Client.php:258

Below is the code.

require_once __DIR__ . '/vendor/autoload.php';
define('APPLICATION_NAME', 'Google Sheets API PHP Quickstart');
define('CREDENTIALS_PATH', '~/.credentials/sheets.googleapis.com-php-quickstart.json');
define('CLIENT_SECRET_PATH', __DIR__ . '/client_secret.json');

For Refresh Token Following code is used.

// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
    $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
    file_put_contents($credentialsPath, json_encode($client->getAccessToken()));
}

I checks the questions on SO this and this. These questions providing same answer which is updated in Sheet API V4.

After following all above solutions i am getting the above error, How can i get rid off from this error?

Hamza Zafeer
  • 2,360
  • 13
  • 30
  • 42

0 Answers0