14

サーバー間の 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]

http://i.stack.imgur.com/iGGYx.png

4

3 に答える 3

12

それを私が直した。

SERVICE_ACCOUNT_EMAIL = 'xxxxxx.apps.googleusercontent.com'

上記は電子メールではなくクライアント ID です。これを修正し、現在は機能しています。

于 2014-05-29T10:42:30.427 に答える