我正在使用谷歌API,并面临以下错误-
未定义的索引:在574中,在/供应商/谷歌/apiclient/src/client. php中过期。
我不知道这个错误意味着什么,当我检查它被写的文件-
if (!isset($this->token['expires_in'])) {
// if the token does not have an "expires_in", then it's considered expired
return true;
}
// If the token is set to expire in the next 30 seconds.
return ($created + ($this->token['expires_in'] - 30)) < time();
您能告诉我这个错误是什么意思,以及我如何解决它吗?
这是我的自定义代码-
if (file_exists($credentialsPath)) {
$accessToken = json_decode(file_get_contents($credentialsPath), true);
} else {
$authUrl = $client->createAuthUrl();
printf("Open the following link in your browser:\n%s\n", $authUrl);
print 'Enter verification code: ';
$authCode = trim(fgets(STDIN));
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
if (!file_exists(dirname($credentialsPath))) {
mkdir(dirname($credentialsPath), 0700, true);
}
file_put_contents($credentialsPath, json_encode($accessToken));
}
$client->setAccessToken($accessToken);
if ($client->isAccessTokenExpired()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
file_put_contents($credentialsPath, json_encode($client->getAccessToken()));
}
1条答案
按热度按时间knpiaxh11#
我很好奇你为什么要用expire_in?为什么不直接检查$client-〉isAccessTokenExpired()呢?客户端库会告诉你它是否过期。它也会考虑时钟偏差。
示例:
如果你真的想检查它,尝试
!isset($this->token['expires_in']]
,因为它听起来像是还没有设置。更新
大胆猜测尝试这个,你可能有问题解析你的文件。