我在谷歌身份验证上遇到问题,它工作了一个月,但几天后我收到了这个错误:
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;
它暂时有效...