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

我的梦境 提交于 2019-12-05 06:33:18

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();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!