2014-03-26 59 views
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); 

回答

0

我只是通過強制不使用Google_Auth_AssertionCredentials緩存解決了類似的問題。 我猜想,試圖和錯誤緩存負載

您$名氣聲明改成這樣:

$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禁止使用緩存。

+0

謝謝,這實際上有效。讓我懷疑這是否是php-api中的一個錯誤,因爲它看起來應該這樣做。 – snjagr