首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在python-social-auth中使用gspread

如何在python-social-auth中使用gspread
EN

Stack Overflow用户
提问于 2017-07-02 10:20:53
回答 1查看 43关注 0票数 0

我正在尝试使用带有python-social-auth的gspread,我遵循了文档中描述的示例,并且我已经创建了这个类来用作凭据存储:

代码语言:javascript
复制
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

在我的代码中,我使用了:

代码语言:javascript
复制
import gspread

credentials = Credentials(access_token=user.social_auth.get_access_token(),
              scope=['https://spreadsheets.google.com/feeds'])
sh = gspread.authorize(credentials)

并使用以下命令询问来自API的任何响应:

代码语言:javascript
复制
sh.get_spreadsheets_feed()

此错误出现在控制台上:

代码语言:javascript
复制
*** 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联系人中获取联系人

代码语言:javascript
复制
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
     'https://www.googleapis.com/auth/contacts.readonly',
     'https://www.googleapis.com/auth/spreadsheets.readonly' 
]

有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2017-07-02 11:02:24

您还必须将这些作用域添加到Python Social Auth设置中:

代码语言:javascript
复制
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
    ...
    'https://www.googleapis.com/auth/spreadsheets.readonly',
    'https://spreadsheets.google.com/feeds',
    'https://www.googleapis.com/auth/drive.file'
]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44866939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档