我在google身份验证时出现问题,它工作了一个月但是几天后我收到了这个错误:
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");
}
我注意到google没有向我发送$ 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
}
编辑:
我想办法做到这一点,就像我不知道刷新了什么是因为我添加了这一行:
if (!isset($accessToken['refresh_token'])) $accessToken['refresh_token'] = 12345678910;
目前有效......
答案 0 :(得分:2)
google身份验证API需要一个名为“access_type”的新显式参数来获取有效的刷新令牌。 使用此参数,您声明您需要离线访问该帐户,并且api为您提供刷新令牌。
下载最新的google PHP SDK,自动处理新的必需参数