SuperAPI AI 工具集

google-workspace

办公与效率

查看项目

更新于 10-15 16:36

技能介绍

Google Workspace 技能概述

本技能通过 OAuth 认证与 Google Drive、Gmail、Calendar 和 Docs 交互,支持文件上传、文件夹管理、邮件搜索、日历搜索和文档操作。

主要能力与使用方式

Google Drive:搜索文件与文件夹(references/drive-search.md,脚本 scripts/gdrive_search.py);上传文件(references/drive-upload.md,脚本 scripts/google_drive_upload.py);创建文件夹结构(references/folder-structure.md,脚本 scripts/gdrive_folder_structure.py);创建客户文件夹(references/create-folder.md,脚本 scripts/create_client_folder.py);搜索转录文件(references/transcript-search.md,脚本 scripts/gdrive_transcript_search.py)。

Gmail:搜索邮件(references/gmail-search.md,脚本 scripts/gmail_search.py)。

Calendar:搜索会议(references/calendar-search.md,脚本 scripts/google_calendar_search.py)。

环境配置

首次认证后 OAuth 凭据保存在本地。所需文件包括:client_secrets.json(来自 Google Cloud Console)、settings.yaml(PyDrive2 配置)、mycreds.txt(自动生成的 OAuth 令牌)。

首次设置步骤:前往 Google Cloud Console;启用 Drive、Gmail、Calendar、Docs API;创建 OAuth 2.0 凭据(桌面应用);下载为 client_secrets.json;运行任意脚本,浏览器打开进行 OAuth 授权。

常用命令示例

搜索客户文件夹:python scripts/gdrive_search.py folder "Microsoft"

上传文件:python scripts/google_drive_upload.py --files *.png --folder "Clients/Acme/Assets"

搜索邮件:python scripts/gmail_search.py --domain "microsoft.com" --days 14

搜索日历:python scripts/google_calendar_search.py "Microsoft" --days-back 30

OAuth 权限范围:drive(完整 Drive 访问)、spreadsheets(Sheets 访问)、documents(Docs 访问)、gmail.readonly(读取邮件)、calendar.readonly(读取日历)。

费用

免费——Google Workspace API 提供宽松的免费配额。

安全说明

凭据处理:client_secrets.json 为 OAuth 应用凭据,切勿提交到 git;mycreds.txt 为用户 OAuth 令牌,切勿提交到 git,应加入 .gitignore;settings.yaml 为 PyDrive2 配置,可提交,不含机密。令牌自动刷新;若泄露,可通过 Google 账户设置撤销。切勿在用户或机器之间共享 OAuth 凭据。

数据隐私:可访问用户的个人 Google Drive、Gmail 和 Calendar;文件可能含有机密商业信息;邮件内容高度敏感,应尽量减少存储;日历事件可能含有私人会议细节;共享云端硬盘访问遵循原有权限。

访问范围:请求最小必要权限,包括 drive(完整读写)、drive.readonly(尽可能优先使用只读)、spreadsheets、documents、gmail.readonly、calendar.readonly。可在 https://myaccount.google.com/permissions 查看或撤销访问。

合规考虑:OAuth 授权需用户明确同意权限范围;GDPR 方面 Google Workspace 数据可能包含欧盟用户 PII;可能存在数据驻留要求;共享云端硬盘需遵守组织共享策略;Google 管理控制台可跟踪 API 访问审计;client_secrets.json 应安全存储,不可放入代码仓库。

故障排除

OAuth 令牌过期:出现“Invalid credentials”或“Token has been expired or revoked”时,删除 mycreds.txt,重新运行脚本触发 OAuth 流程,完成浏览器授权,新的 mycreds.txt 会自动生成。

文件未找到:出现“File not found”时,核实 Google Drive URL 中的文件 ID、检查共享权限、确保 OAuth 用户有权访问,可先在浏览器中直接访问该文件。

配额超限:出现“User rate limit exceeded”或“Quota exceeded”时,等待 24 小时配额重置、创建新 Google Cloud 项目获得新配额、在脚本中实现指数退避、降低 API 调用频率。

settings.yaml 缺失:出现“settings.yaml not found”或 PyDrive2 配置错误时,可从模板复制(cp settings.yaml.example settings.yaml)、确认 settings 中 client_secrets.json 路径正确、验证 save_credentials_backend 设为 "file"、检查 settings.yaml 位于脚本工作目录。

client_secrets.json 无效:出现“Invalid client secrets”时,从 Google Cloud Console 重新下载、确保创建凭据时选择“桌面应用”类型、检查 JSON 格式有效、确认重定向 URI 已为本地认证配置。

权限范围访问被拒:出现“Insufficient permission”时,删除 mycreds.txt 重置 OAuth 会话、重新认证并接受所有请求的权限、验证 settings.yaml 中的权限与脚本需求一致、检查 Google Cloud Console 中的权限限制。

集成模式

Drive 到视频制作(google-workspace → video-production):用于从 Drive 文件夹组装课程视频。流程:搜索包含课程文件的视频文件夹;通过 video-production 脚本下载视频;拼接视频并添加标题幻灯片,上传最终输出。

模板到内容(google-workspace → content-generation):用于从品牌模板生成文档。流程:从 Drive 加载模板(提案、报告格式);通过 content-generation 生成内容;创建含格式化内容的新 Google Doc。

日历到转录(google-workspace → transcript-search):用于从日历事件查找会议录像。流程:在日历中搜索特定客户的会议;获取会议日期和标题;在 transcript-search 中搜索匹配的录像。

资源文件

references/drive-search.md、references/drive-upload.md、references/folder-structure.md、references/create-folder.md、references/transcript-search.md、references/gmail-search.md、references/calendar-search.md。