在没有 Google Drive Scope 的情况下创建电子表格

问题描述 投票:0回答:1

有什么方法可以只使用 Gspread 中的范围

https://www.googleapis.com/auth/spreadsheets
创建电子表格吗?

根据文档,范围本身似乎可以处理“创建”:

Google scope documentation

请建议与此问题相关的示例代码或网站

python google-api spreadsheet gspread
1个回答
0
投票

是的,您可以仅使用以下范围之一使用 Google API 创建电子表格:

  • https://www.googleapis.com/auth/drive
  • https://www.googleapis.com/auth/drive.file
  • https://www.googleapis.com/auth/spreadsheets

来源:https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/create


仅当您打算将文件保存到特定文件夹时才需要 Google Drive 权限范围。否则,您可以直接使用

https://www.googleapis.com/auth/spreadsheets
范围保存到根目录。

虽然可以在 GSpread 中传入自定义范围:

# Use one of the following, depends on your use case
gspread.oauth(scopes=['https://www.googleapis.com/auth/drive'])
gspread.service_account(scopes=['https://www.googleapis.com/auth/drive'])

来源:https://docs.gspread.org/en/latest/api/top-level.html


但是,在源代码中:https://github.com/burnash/gspread/blob/50b910f2911c6203e139934bafbbce9fe300e8e1/gspread/client.py#L228

它使用 Google Drive API 而不是使用 Google Sheets API 创建电子表格,这就是为什么它需要

https://www.googleapis.com/auth/drive
范围

© www.soinside.com 2019 - 2024. All rights reserved.