2011-12-12 73 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