gpt4 book ai didi

google-cloud-datastore - 在 oauth2 SignedJwtAssertionCredentials 中得到 'invalid_grant'

转载 作者:行者123 更新时间:2023-12-02 02:00:40 25 4
gpt4 key购买 nike

我正在尝试在服务器到服务器 JSON API 场景中创建 oauth2 access_token。但它失败并出现 invalid_grant 错误,请帮忙。

from oauth2client.client import SignedJwtAssertionCredentials

KEY_FILE = 'xxxxxxxxxxxx-privatekey.p12'

with open(KEY_FILE, 'r') as fd:
key = fd.read()

SERVICE_ACCOUNT_EMAIL = 'xxxxxx.apps.googleusercontent.com'

credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL, key,
scope="https://www.googleapis.com/auth/datastore https://www.googleapis.com/auth/userinfo.email",
token_uri='https://accounts.google.com/o/oauth2/token')


assertion = credentials._generate_assertion()

h = httplib2.Http()
credentials._do_refresh_request(h.request)

我得到了

Traceback (most recent call last):
File "/Users/pahud/Projects/oauth2client/x.py", line 24, in <module>
credentials._do_refresh_request(h.request)
File "/Users/pahud/Projects/oauth2client/oauth2client/client.py", line 710, in _do_refresh_request
raise AccessTokenRefreshError(error_msg)
oauth2client.client.AccessTokenRefreshError: invalid_grant
[Finished in 0.7s with exit code 1]

/image/iGGYx.png

最佳答案

我修好了。

SERVICE_ACCOUNT_EMAIL = 'xxxxxx.apps.googleusercontent.com'

上面是客户端 ID,而不是电子邮件,我修复了这个问题,现在可以使用了。

关于google-cloud-datastore - 在 oauth2 SignedJwtAssertionCredentials 中得到 'invalid_grant',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23918443/

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