3

According to the following post #244 to authenticate the credential we can define GOOGLE_APPLICATION_CREDENTIALS environment variable to directly authenticate.

Here is what I did in my code.

import gspread
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
credentials.create_scoped(['https://spreadsheets.google.com/feeds'])
gc = gspread.authorize(credentials)
wks = gc.open("hello").sheet1

But when I run this it raises an oauth2client.client.HttpAccessTokenRefreshError: invalid_grant

Any suggestions on how to resolve this?

Thanks,

Lin
  • 1,547
  • 2
  • 12
  • 26

1 Answers1

0

This might be an issue with server time (run "date" command). I would suggest setting up NTP on your server to have it update time automatically.

CentOS NTP http://www.cyberciti.biz/faq/howto-install-ntp-to-synchronize-server-clock/

Ubuntu NTP https://www.digitalocean.com/community/tutorials/how-to-set-up-time-synchronization-on-ubuntu-12-04

Robert Lee
  • 1,541
  • 1
  • 10
  • 20
  • Hi @Robert, I think this is not a time issue. When I ran the date command, nothing is wrong. Will above code work in your system? – Lin Jan 29 '16 at 04:48
  • Yes. I updated NTP on my server and updated the time. It fixed this specific issue. – Robert Lee Jan 29 '16 at 17:43
  • I have figured out the problem here. I first got SpreadsheetNotFound exception, then I added my own email to the client_email entry in my credential file, which caused this problem. Instead I should shared my spread sheet with the client email address listed in the credential file. – Lin Jan 30 '16 at 21:01
  • Good to know you figured it out – Robert Lee Jan 30 '16 at 21:12