我正在使用OAuth为Google日历创建服务器应用。现在它最初工作正常,当访问令牌过期并且无法更新其自身时出现问题。我以为我已经用isAccessTokenExpired()子句覆盖...
$client->setAccessType('offline');
$client->setScopes(array('https://www.googleapis.com/auth/calendar'));
if (isset($_SESSION['token'])) {$client->setAccessToken($_SESSION['token']);}
/* GOOGLE OAUTH *////-----------------------------------------
$pkey = file_get_contents($pkey_file);
$cred = new Google_Auth_AssertionCredentials(
$service_acct,
array('https://www.googleapis.com/auth/calendar'),
$pkey );
$cred->sub = "xxxxxxxxxx@x";
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['token'] = $client->getAccessToken();
/* ------ *////---------------------------------------------
$cal = new Google_Service_Calendar($client);
答案 0 :(得分:0)
我刚刚通过强制不使用Google_Auth_AssertionCredentials中的缓存解决了类似的问题。 我想在尝试和错误时加载缓存
将您的$ cred声明更改为:
$cred = new Google_Auth_AssertionCredentials($service_acct, array('https://www.googleapis.com/auth/calendar'), $pkey, 'notasecret','http://oauth.net/grant_type/jwt/1.0/bearer',false,false
);
最后false
禁用缓存。