gpt4 book ai didi

php - 谷歌服务帐户示例返回 "Error refreshing the OAuth2 token { “error” : “invalid_grant” }"

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:53:03 25 4
gpt4 key购买 nike

我的目标是代表我的网络应用程序用户在 Google Fusion Tables 上进行最简单的查询。为此,我在 Google 控制台上创建了一个服务帐户。这是代码:

    // Creating a google client
$client = new \Google_Client();


// setting the service acount credentials
$serviceAccountName = 'XXXXX.apps.googleusercontent.com';
$scopes= array(
'https://www.googleapis.com/auth/fusiontables',
'https://www.googleapis.com/auth/fusiontables.readonly',
);
$privateKey=file_get_contents('/path/to/privatekey.p12');
$privateKeyPassword='notasecret'; // the default one when generated in the console

$credential = new \Google_Auth_AssertionCredentials($serviceAccountName,
$scopes, $privateKey, $privateKeyPassword);

// setting assertion credentials
$client->setAssertionCredentials($credential);

$service = new \Google_Service_Fusiontables($client);
$sql = 'select name from XXXXXXXX';
$result = $service->query->sql($sql);

运行这段代码后,我得到了这个错误:

Error refreshing the OAuth2 token, message: '{
"error" : "invalid_grant"
}'

我在谷歌上搜索了好几天,大多数答案都在谈论刷新 token 。我进行了此刷新,但仍然出现相同的错误!

有解决这个问题的想法吗?谢谢

最佳答案

在我的情况下,这是由于服务器时间太远(大约 5 分钟)造成的。

虽然您的问题已经解决,但也许这对将来登陆这里的人有任何帮助,因为 Google 返回的错误是相同的。

关于php - 谷歌服务帐户示例返回 "Error refreshing the OAuth2 token { “error” : “invalid_grant” }",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24572077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com