google服务帐户示例返回“刷新OAuth2令牌时发生错误{“ error”:“ invalid_grant”}“

阿米·贾卢里(Amine Jallouli)

我的目标是Google Fusion Tables代表我的Web应用程序用户进行最简单的查询为此,我在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"
}'

我用谷歌搜索了好几天,大多数答案都在谈论刷新令牌。我做了刷新,但仍然是相同的错误!

有解决这个问题的主意吗?谢谢

阿米·贾卢里(Amine Jallouli)

我知道许多人都面临着与我相同的问题。因此,这是在Google上搜索几天后的解决方案。

我提出的代码只有一个错误:客户端ID类似于电子邮件,类似于 [email protected]

您要做的第二件事是与服务帐户的客户ID共享您在google融合表中查询的表。

在那之后,事情将完美地进行。

我希望这会帮助其他人。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Google Oauth2:刷新OAuth2令牌时出错,消息:'{“ error”:“ invalid_grant”}'

Google Api服务帐户“错误”:“ invalid_grant”,“ error_description”:“无效的JWT签名”。

Google Oauth刷新令牌-invalid_grant

'刷新OAuth2令牌时出错,消息:实时网站上的消息:'{“ error”:“ invalid_grant”}'',但在本地环境下有效

Spring Boot: error="invalid_grant", error_description="错误的凭据"

Google Directory API PHP客户端SDK出现{“ error”:“ invalid_grant”}错误

Google oAuth2访问令牌:“ invalid_grant”

Google API OAuth2,服务帐户,“错误”:“ invalid_grant”

刷新访问令牌时出现“ invalid_grant”错误的情况?

错误:“invalid_grant”Angular 5

Google_Auth_Exception:invalid_grant

invalid_grant试图从Google获取oAuth令牌

OAUth2 ASP.NET invalid_grant

Google Calendar API返回invalid_grant和错误的请求

尝试获取访问令牌googleapi的Invalid_grant错误

Invalid_grant 请求访问令牌 MS Graph 时

Analytics API返回:错误的请求-invalid_grant

尝试为Box API使用oAuth2时出现invalid_grant错误

Google云端存储HttpAccessTokenRefreshError:invalid_grant:错误的请求

(400)错误的请求:获取Salesforce的AccessToken错误:“ invalid_grant”

Spotify SessionManager持续失败,并显示错误“ invalid_grant”

docusign nodejs 客户端的 invalid_grant 错误

'invalid_grant:无效的JWT:Google翻译API

HttpAccessTokenRefreshError:invalid_grant ...一小时限制刷新令牌

为什么我在 Google 的 Python TTS 示例中收到“invalid_grant: Invalid JWT Signature”?

条纹 API;{'error': 'invalid_grant', 'error_description': '此授权码已被使用

加入 Office365 Outlook OAuth 时出现 invalid_grant 错误

pydrive.auth.RefreshError:访问令牌刷新失败:invalid_grant:令牌已过期或吊销

为什么“获取用户访问权”令牌会引发invalid_grant错误?