Getting AccessTokenRefreshError: invalid_grant in Google API fro service account

女生的网名这么多〃 提交于 2019-12-07 03:52:26

问题


I am following this example

https://code.google.com/p/google-api-python-client/source/browse/samples/service_account/tasks.py

  credentials = SignedJwtAssertionCredentials(
      '141491975384@developer.gserviceaccount.com',
      key,
      scope='https://www.googleapis.com/auth/tasks')
  http = httplib2.Http()
  http = credentials.authorize(http)

  service = build("tasks", "v1", http=http)

  # List all the tasklists for the account.
  lists = service.tasklists().list().execute(http=http)
  pprint.pprint(lists)

The issue is , it works sometimes and i get the lists as JSON and after running program few more times i get error

  File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 710, in _do_refresh_request
    raise AccessTokenRefreshError(error_msg)
oauth2client.client.AccessTokenRefreshError: invalid_grant

回答1:


I'm interface Google Drive but found the same error. In Issue 160 there is a report of setting the appropriate time on your local computer. Ever since I upgraded to Mac Mavericks I found that the I need to keep updating my system time. I was getting your reported error, set my system time back to current and I eliminated the error.




回答2:


Are you running this code in a VM or sandboxed environment? If so, it could just be that your VM's clock isn't synchronised to your host machine. See a response to a similar question here.

I suffered the same (frustrating) problem and found that simply restarting my VM (ensuring the time was synchronised to the host machine (or at least set to the local timezone) fixed the problem.




回答3:


Oauth service is highly dependent on the time, make sure your client uses NTP or another time syncing mechanism.

Test with curl -I https://docs.google.com/ ; date -u

You should see the same Date: (or whithin a few seconds) for this to work



来源:https://stackoverflow.com/questions/18347959/getting-accesstokenrefresherror-invalid-grant-in-google-api-fro-service-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!