python gspread 授权 oauth2 凭证

标签 python oauth gspread

如何让 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/

相关文章:

python - 这段代码背后的逻辑是如何运作的?

facebook - 处理存在的用户,但尝试通过 Facebook OAuth/etc 登录

python - gspread findall() 仅在 1 列内

python - crontab 找不到 python 模块

python - 获取长度(/基数)为 1 的集合项而不删除它的首选 Python 方法?

Ruby google_drive gem oAuth2 保存

python - 从 Google 表格中检索链接的值?

python - 如何在 python 中将 wrap_strategy 用于谷歌表格?

Python提取可量化文本(数字)

java - 使用 Scribe for LinkedIn 进行 oAuth - accessToken 问题