python-3.x - 有什么方法可以使用python通过api删除完整的电子表格
问题描述
我有我从 python 创建的电子表格的谷歌电子表格 ID,但我找不到任何方法从 python API 中删除该文件 我正在使用这里的代码
“我期待一种方法可以传递 spreadSheetId,它将删除包含该 ID 的电子表格”
解决方案
# Authentication to Google Sheet API & Google Drive API
scopes = [
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/script.external_request"
]
credentials = service_account.Credentials.from_service_account_file(my_secret_file, scopes=scopes)
sheets_service = discovery.build('sheets', 'v4', credentials=credentials, cache_discovery=False)
drive_service = discovery.build('drive', 'v3', credentials=credentials, cache_discovery=False)
# Now delete. We only need the drive_service
drive_service.files().delete(fileId='your spreadsheet id').execute()
推荐阅读
- c# - 有没有办法轻松地将大量依赖 SqlConnection 的代码切换到 MySqlConnection
- parsing - 如何绘制解析树?
- python - 无法在 Django 2.xx Python AppEngine 中连接到 MySQL 服务器
- r - 安装包时将脚本的路径放在环境变量中
- c++ - QtCreator / GDB 调试器:不可访问,或“this”对象未显示
- python-3.x - 即使满足“if”条件,为什么“else”代码仍在运行
- actionscript - 使用 Adobe Indesign Scripting 使用 ActionScript 编写文件时如何获取换行符
- javascript - 在 dexie.js 中如何获取表中的所有记录?
- c# - 将 VirtualizingStackPanel 与 ScrollViewer 内的多个 ListBox 一起使用
- php - Mysqli 连接查询返回错误的 COUNT?