2011-12-12 76 views
1

我得到了谷歌的問題進行身份驗證,它的工作了一個月,但由於幾天我得到這個錯誤:谷歌認證

Fatal error: Uncaught exception 'apiAuthException' with message 
'Invalid token format' in /home/project/html/google/auth/apiOAuth2.php:127 Stack trace: 
#0 /home/project/html/google/auth/apiOAuth2.php(89): apiOAuth2->setAccessToken('{? "access_tok...') 
#1 /home/project/html/google/apiClient.php(132): apiOAuth2->authenticate(Array) 
#2 /home/project/html/hk/connects/google.php(22): apiClient->authenticate() 
#3 {main} thrown in /home/project/html/google/auth/apiOAuth2.php on line 127 

在apiOAuth2.php我的代碼:

$accessToken = json_decode($accessToken, true); 
if (! isset($accessToken['access_token']) || ! isset($accessToken['expires_in']) || ! isset($accessToken['refresh_token'])) { 
    throw new apiAuthException("Invalid token format"); 
} 

我注意到谷歌不會給我$ accessToken ['refresh_token']。 它似乎並沒有來自谷歌,因爲我做了http://stackoverflow.com

正確的聯接也許這是我的代碼原因:

session_start(); 

$client = new apiClient(); 
$plus = new apiPlusService($client); 

if (!isset($_GET['code'])) { 
    header('Location: '.$client->createAuthUrl()); // Calls the same page 
} else { 
    $client->authenticate(); // Fails at this level 
} 

編輯:

我想出一個辦法做到這一點,就像我不知道什麼是refresh_token做出了我加入這一行:

if (!isset($accessToken['refresh_token'])) $accessToken['refresh_token'] = 12345678910; 

它適用於當下...

+0

我想出了一個辦法,看我的編輯。 – user1040899

+0

你能分享一些你的代碼,我一直在嘗試,但我無法克服那個致命的錯誤,謝謝 – Patrioticcow

+0

您好Patrioticcow,在apiOAuth2.php你搜索代碼$ accessToken = json_decode($ accessToken,true);並在你的下方添加我在我的評論中編輯的代碼。 – user1040899

回答

2

有一個新的顯式參數叫做「access_type」,它需要google認證api來獲得一個有效的刷新令牌。 使用此參數可以聲明您需要對該帳戶進行脫機訪問,並且API會爲您提供刷新令牌。

下載最新的谷歌PHP SDK,自動處理新的所需參數

+0

好的,謝謝你我會試試! – user1040899