0
我正在使用OAuth爲Google日曆創建服務器應用程序。現在它最初工作正常,當訪問令牌過期並且無法更新其自身時出現問題。我原本以爲是覆蓋isAccessTokenExpired()子句...Google OAuth2令牌錯誤
$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 = "[email protected]";
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['token'] = $client->getAccessToken();
/* ------ *////---------------------------------------------
$cal = new Google_Service_Calendar($client);
謝謝,這實際上有效。讓我懷疑這是否是php-api中的一個錯誤,因爲它看起來應該這樣做。 – snjagr