在oauth2 SignedJwtAssertionCredentials中得到'invalid_grant' [英] got 'invalid_grant' in oauth2 SignedJwtAssertionCredentials
问题描述
我试图在服务器到服务器的JSON API场景中创建一个oauth2 access_token。但它失败了invalid_grant错误,请帮助。
from oauth2client.client import SignedJwtAssertionCredentials
KEY_FILE = 'xxxxxxxxxxxx-privatekey.p12'
打开(KEY_FILE,'r')作为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 =凭证。 _generate_assertion()
h = httplib2.Http()
credentials._do_refresh_request(h.request)
我得到了
$ b $ pre $ Traceback(最近一次调用最后一次):
File/用户/ pahud / Projects / oauth2client / x.py,第24行,位于< module>
credentials._do_refresh_request(h.request)
文件/Users/pahud/Projects/oauth2client/oauth2client/client.py,第710行,在_do_refresh_request
中引发AccessTokenRefreshError(error_msg)
oauth2client.client.AccessTokenRefreshError:invalid_grant
[在0.7s以退出代码1完成]
http://i.stack.imgur.com/iGGYx.png
我解决了这个问题。
SERVICE_ACCOUNT_EMAIL ='xxxxxx.apps.googleusercontent.com'
以上是客户端ID不是Email,我解决了这个问题,现在它正在工作。
I am trying to make an oauth2 access_token in a server-to-server JSON API scenario. But it failed with invalid_grant error, please help.
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)
and I got
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]
http://i.stack.imgur.com/iGGYx.png
I fixed it.
SERVICE_ACCOUNT_EMAIL = 'xxxxxx.apps.googleusercontent.com'
the above is client ID not Email, I fixed this and it's working now.
这篇关于在oauth2 SignedJwtAssertionCredentials中得到'invalid_grant'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!