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

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

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

invalid_scope: https://spreadsheets.google.com/feeds is not a valid audience string.

最初,我将范围作为列表,但是,我在 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())`

最佳答案

错误非常明显:spreadsheets.google.com/feeds 不是 API 范围。

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

这些都很好地制成了表格:

Scope Meaning
https://www.googleapis.com/auth/spreadsheets.readonly Allows read-only access to the user's sheets and their properties.
https://www.googleapis.com/auth/spreadsheets Allows read/write access to the user's sheets and their properties.
https://www.googleapis.com/auth/drive.readonly Allows read-only access to the user's file metadata and file content.
https://www.googleapis.com/auth/drive.file Per-file access to files created or opened by the app.
https://www.googleapis.com/auth/drive Full, permissive scope to access all of a user's files. Request this scope only when it is strictly necessary.

关于python - invalid_scope : https://spreadsheets. google.com/feeds 不是有效的受众字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49829002/

相关文章:

javascript - 为什么我不能从 POST 请求中提取 zip 文件?

javascript - 使用drive.files.export(Drive API v3)+ API key 获取文本/纯格式的公共(public)Google文档内容

flutter - 如何在 Google 表格中接受可变数量的参数

PHP Google Sheets API - 权限被拒绝

python - 在Python SQLite语句中插入字符串

Python - 相当于 Matlab/Octave 键盘功能?

python - pyspark.sql.utils.IllegalArgumentException : 'requirement failed: Invalid initial capacity'

python - 如何从 pyspark 中的 spark sql 查询调用用户定义的函数?

google-drive-api - 使用 Drive API 获取文件内容

google-sheets-api - 使用 Google Sheets API 中的范围规则之一进行数据验证