Uncaught exception 'Google_Auth_Exception' with message 'Could not json decode the token' Uncaught exception 'Google_Auth_Exception' with message 'Could not json decode the token' json json

Uncaught exception 'Google_Auth_Exception' with message 'Could not json decode the token'


I have encountered the same problem. It seems that the latest Google API PHP library is expecting a json encoded token in the setAccessToken method. So what I did as a work around was encoded the tokens to json.

// $token could be retrieved from your SESSION cookie or from your DB.$token = array(    'access_token' => 'XXXXXXX',    'refresh_token' => 'XXXXXXX');$json_token = json_encode($token);$client->setAccessToken($json_token);

Hope this helps.


Could you Copy-paste your $_SESSION['access_token']?

Try with this:

http://php.net/manual/es/function.json-last-error.php

In your code, change:

json_decode($_SESSION['access_token']);if (isset($_SESSION['access_token']) && $_SESSION['access_token'] && !json_last_error()) {  $client->setAccessToken($_SESSION['access_token']);} else {  $authUrl = $client->createAuthUrl();}