SuperAPI AI 工具集

google-docs-manager

办公与效率

查看项目

更新于 10-16 06:51

技能介绍

用途:让 AI 代理以编程方式操作 Google Docs,无需浏览器交互,适合自动化文档读写场景。可创建文档、按关键词查找文档、读取正文、追加或插入文本、查找替换文本,以及将文档移入回收站或永久删除。不适用于下载二进制文件或管理非 Docs 文件,后者应改用 google-drive-manager。

准备工作:需要启用 Docs API 与 Drive API 的 Google Cloud 项目,以及服务账号 JSON 密钥文件;设置 GOOGLE_CREDENTIALS_PATH=/path/to/credentials.json,并安装依赖 pip install -r requirements.txt。

主要命令:创建 python scripts/docs.py create "Title" [--content "text"];查找 python scripts/docs.py find "query" [--limit 10];读取 python scripts/docs.py get-text <doc_id>;追加 python scripts/docs.py append-text <doc_id> "text";开头插入 python scripts/docs.py insert-text <doc_id> "text";替换 python scripts/docs.py replace-text <doc_id> "old" "new";删除 python scripts/docs.py delete <doc_id>(默认移入回收站,加 --permanent 永久删除)。鉴权管理:python scripts/auth.py status 检查凭据文件,python scripts/auth.py validate 测试 API 连通性。

输出为结构化 JSON,含 status 与 message,成功时带 data。使用时须先检查 status;编辑前先用 find 获取准确 doc_id,切勿猜测;用 get-text 读取现有内容后再做定向修改;定向修改优先用 replace-text,新增内容用 append-text;默认删除只移入回收站,仅在用户明确要求时使用 --permanent。doc_id 是 Google Docs 链接 https://docs.google.com/document/d/<doc_id>/edit 中的字母数字串,不要直接使用完整 URL。

常见错误:猜测 doc_id、未读先改、默认永久删除、把完整 URL 当 doc_id、该替换却追加。限制:资料未提供配额、权限范围、速率限制及收费信息。