如何让 gspread 使用我的 oauth 凭据?我的 http 响应 gspread.httpsession.HTTPError 出现错误:( 谁能告诉我我的代码有什么问题吗?
import datetime
import gspread
import json
import MySQLdb
from oauth2client.client import OAuth2Credentials
# Get access token from database
data = json.loads(row['access_token'])
credentials = OAuth2Credentials(
data['access_token'],
"1*************************k.apps.googleusercontent.com",
"9t*****************W",
data['refresh_token'],
datetime.datetime.now(),
"https://accounts.google.com/o/oauth2/token",
'user-agent'
)
gc = gspread.authorize(credentials)
wks = gc.open_by_key('1*****************W')
其中行包含来自数据库的数据(它具有 google oauth 返回的访问 token )?米(_ _)米
最佳答案
我在使用 Oauth2Credentials 进行身份验证时也遇到了麻烦。我的建议是使用googles创建凭据的 Oauth2 工作流程。此外,请确保使用“https://spreadsheets.google.com/feeds” ' 作为凭证的范围。
我目前正在使用此流程,并且我的通话工作正常。
关于python gspread 授权 oauth2 凭证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26155547/