【发布时间】:2017-07-02 11:02:24
【问题描述】:
我正在尝试将 gspread 与 python-social-auth 一起使用,我按照文档中的示例描述进行操作,并创建了此类用作凭据存储:
class Credentials(object):
def __init__ (self, access_token=None, scope=None):
self.access_token = access_token
self.scope=scope
def refresh (self, http):
# get new access_token
# this only gets called if access_token is None
pass
在我使用的代码中:
import gspread
credentials = Credentials(access_token=user.social_auth.get_access_token(),
scope=['https://spreadsheets.google.com/feeds'])
sh = gspread.authorize(credentials)
并使用以下方式询问 API 的任何响应:
sh.get_spreadsheets_feed()
控制台上出现此错误:
*** RequestError: (401, '401: <HTML>\n<HEAD>\n<TITLE>Token invalid - AuthSub token has wrong scope</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Token invalid - AuthSub token has wrong scope</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n')
我已经在我的设置中定义了范围,并且效果很好,例如尝试从 Google 通讯录中获取联系人
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
'https://www.googleapis.com/auth/contacts.readonly',
'https://www.googleapis.com/auth/spreadsheets.readonly'
]
有什么想法吗?
【问题讨论】:
标签: python-social-auth gspread