【问题标题】:invalid_scope: https://spreadsheets.google.com/feeds is not a valid audience stringinvalid_scope:https://spreadsheets.google.com/feeds 不是有效的受众字符串
【发布时间】:2018-04-14 07:33:51
【问题描述】:

我正在尝试使用 OAuth2 和 gspread 来使用 Python 来操作 Google 表格。但是,我一直遇到这个错误:

invalid_scope:https://spreadsheets.google.com/feeds 不是有效的受众字符串。

最初,我将范围作为一个列表,但是,我在 StackOverflow 上看到另一个答案,说范围应该是一个以空格分隔的字符串。我试着改过,但错误仍然发生。

这是我的代码:

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ' '.join(['https://spreadsheets.google.com/feeds', 'https://googleapis.com/auth/drive'])

credentials = ServiceAccountCredentials.from_json_keyfile_name("SpreadsheetExample-bec536232207.json", 'https://spreadsheets.google.com/feeds https://googleapis.com/auth/drive')

gc = gspread.authorize(credentials)
wks = gc.open("test").sheet1

print(wks.get_all_records())`

【问题讨论】:

    标签: python google-drive-api google-sheets-api google-oauth gspread


    【解决方案1】:

    错误很明确:spreadsheets.google.com/feeds 不是 API 范围。

    如果您想请求访问 Google 表格文件的权限,请使用表格 REST API 文档中列出的一个或多个 API 范围: https://developers.google.com/sheets/api/guides/authorizing#OAuth2Authorizing

    这些都很好地列出了:

    范围含义
    https://www.googleapis.com/auth/spreadsheets.readonly允许只读访问用户的工作表及其属性。
    https://www.googleapis.com/auth/spreadsheets 允许对用户的工作表及其属性进行读/写访问。
    https://www.googleapis.com/auth/drive.readonly 允许对用户的文件元数据和文件内容进行只读访问。
    https://www.googleapis.com/auth/drive.file 对应用创建或打开的文件的按文件访问。
    https://www.googleapis.com/auth/drive 访问用户所有文件的完全许可范围。仅在绝对必要时才请求此范围。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-19
      • 1970-01-01
      • 2022-08-17
      • 2012-10-11
      • 2022-08-17
      • 2017-03-13
      • 2013-11-28
      相关资源
      最近更新 更多