谷歌认证

发布于 2024-12-21 02:10:58 字数 1484 浏览 3 评论 0原文

我在谷歌验证上遇到了问题,它工作了一个月,但几天后我收到了这个错误:

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
}

编辑:

我想出了一种方法来做到这一点,就像我不知道刷新令牌是什么,因为我添加了这一行:

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

它目前有效......

I got a problem on google authenticate, it worked for a month but since a few days I got this error :

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

In apiOAuth2.php I have the code :

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

I noticed that google doesn't send me the $accessToken['refresh_token'].
It doesn't seem to come from google cause I did a correct connexion on http://stackoverflow.com

Maybe it's cause of my code :

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
}

EDIT:

I figured a way to do it, like I don't know what is refresh_token made for I added this line :

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

It works for the moment...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少年亿悲伤 2024-12-28 02:10:58

google 身份验证 API 需要一个名为“access_type”的新显式参数来获取有效的刷新令牌。
使用此参数,您声明您需要离线访问该帐户,并且 api 为您提供刷新令牌。

下载最新的 google PHP SDK,它会自动处理新的所需参数

There is a new explicit parameter called "access_type" required by the google authentication api to obtain a valid refresh token.
With this parameter you declare that you need offline access to the account and the api provides you a refresh token.

Download the latest google PHP SDK that automatically handles the new required parameter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文