根据以下帖子#244要验证凭据,我们可以定义 GOOGLE_APPLICATION_CREDENTIALS 环境变量来直接进行身份验证。
这是我在代码中所做的。
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
但是当我运行它时它会引发 oauth2client.client.HttpAccessTokenRefreshError: invalid_grant
关于如何解决这个问题有什么建议吗?
谢谢,
最佳答案
这可能是服务器时间的问题(运行“date”命令)。我建议在您的服务器上设置 NTP 以使其自动更新时间。
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
关于python gspread oauth2client.client.HttpAccessTokenRefreshError : invalid_grant 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34867516/