openclaw/gogcli

GitHub: openclaw/gogcli

将 Gmail、Drive、Docs、Sheets、Calendar 等 Google Workspace 服务统一到终端的脚本友好型 CLI,专为自动化、CI 和编程智能体设计。

Stars: 7738 | Forks: 614

# gogcli `gog` 是一个对脚本友好的 Google CLI,支持 Gmail、Calendar、Drive、Docs、Sheets、Sites、Slides、Forms、Meet、Apps Script、Analytics、Search Console、Contacts、Tasks、People、Classroom、Chat、YouTube 以及 Workspace 管理流程。 它专为终端、shell 脚本、CI 和编程智能体打造: - 在 stdout 上提供可预测的 `--json` 和 `--plain` 输出 - 在 stderr 上提供人工提示和进度信息 - 支持多个 Google 账号和 OAuth 客户端 - 支持 OAuth、直接访问令牌、ADC 和 Workspace 服务账号 - 支持运行时命令的允许列表/拒绝列表以及内置安全配置文件的二进制文件 - 为 Drive 和 Contacts 等风险面提供只读的审计/报告命令 - 为每个命令提供[生成的文档](docs/commands/README.md) 渲染的文档: 在此开始: - [安装](docs/install.md) - [快速开始](docs/quickstart.md) - [Auth 客户端和服务账号](docs/auth-clients.md) - [命令索引](docs/commands/README.md) - [Gmail watch / Pub/Sub push](docs/watch.md) () ## 安装 有关 Homebrew、Docker、Windows ZIP 压缩包、源码构建以及无头/容器密钥环设置的完整指南,请参阅 [安装](docs/install.md)。 ### Homebrew ``` brew install gogcli gog --version ``` ### Docker ``` docker run --rm ghcr.io/openclaw/gogcli:latest version ``` 带有身份验证的容器运行应使用持久化配置卷和加密文件密钥环: ``` docker volume create gogcli-config docker run --rm -it \ -e GOG_KEYRING_BACKEND=file \ -e GOG_KEYRING_PASSWORD \ -v gogcli-config:/home/gog/.config/gogcli \ ghcr.io/openclaw/gogcli:latest \ auth add you@gmail.com --services gmail,calendar,drive ``` ### Windows 从[最新发布版](https://github.com/openclaw/gogcli/releases)下载 `gogcli__windows_amd64.zip` 或 `gogcli__windows_arm64.zip`,解压 `gog.exe`,并将该目录添加到 `PATH` 中。 ### 从源码构建 ``` git clone https://github.com/openclaw/gogcli.git cd gogcli make ./bin/gog --version ``` 源码构建需要在 `go.mod` 中声明的 Go 版本。 ## 快速开始 完整的演练步骤请参阅 [快速开始](docs/quickstart.md)。有关命名的 OAuth 客户端、远程 OAuth、直接访问令牌、ADC 和 Workspace 服务账号,请参阅 [Auth 客户端](docs/auth-clients.md)。 创建一个 Google Cloud 项目,启用你需要的 API,创建一个 Desktop OAuth 客户端,然后将该客户端 JSON 存储在 `gog` 中。 ``` gog auth credentials ~/Downloads/client_secret_....json gog auth add you@gmail.com --services gmail,calendar,drive,docs,sheets,contacts gog auth doctor --check export GOG_ACCOUNT=you@gmail.com gog gmail search 'newer_than:7d' --max 10 ``` 有用的 Google 设置链接: - [创建 Cloud 项目](https://console.cloud.google.com/projectcreate) - [OAuth 客户端](https://console.cloud.google.com/auth/clients) - [OAuth 同意屏幕](https://console.cloud.google.com/auth/branding) - [API 库](https://console.cloud.google.com/apis/library) - [Places API (New)](https://console.cloud.google.com/apis/api/places.googleapis.com) - [Drive Labels API](https://console.cloud.google.com/apis/api/drivelabels.googleapis.com) - [Photos Library API](https://console.cloud.google.com/apis/api/photoslibrary.googleapis.com) - [Google Analytics Admin API](https://console.cloud.google.com/apis/api/analyticsadmin.googleapis.com) - [Google Analytics Data API](https://console.cloud.google.com/apis/api/analyticsdata.googleapis.com) - [Google Search Console API](https://console.cloud.google.com/apis/api/searchconsole.googleapis.com) - [YouTube Data API v3](https://console.cloud.google.com/apis/api/youtube.googleapis.com) - [Apps Script 用户设置](https://script.google.com/home/usersettings) 在与你的 OAuth 客户端所属的同一个 Cloud 项目中启用 API。如果 Google 返回 `accessNotConfigured`,请启用该 API 并在传播完成后重试。 消费者 `gmail.com` 账号可用于普通用户 API,例如 Gmail、Calendar、Drive、Docs、Sheets、Slides、Forms、Apps Script、Analytics、Search Console、Contacts/People、Tasks 和 Classroom。仅限 Workspace 的 API(如 Admin Directory、Cloud Identity Groups、Chat 和 Keep/全域委派流程)则需要托管域名。 如果你的 OAuth 应用处于 External + Testing 状态,Google 针对用户数据作用域的 refresh token 可能会在 7 天后过期。如果你希望 refresh token 长期有效,请发布该个人 OAuth 应用。 ## 日常示例 下面的每个命令都在[命令索引](docs/commands/README.md)中提供了生成的参考文档。每个部分下链接的功能指南解释了工作流程形态和安全注意事项。 ### Gmail 文档: [Gmail 工作流](docs/gmail-workflows.md), [Gmail watch](docs/watch.md), [邮件跟踪](docs/email-tracking.md), [`gog gmail`](docs/commands/gog-gmail.md)。 ``` # 搜索邮件并为 agents/scripts 获取经过净化的消息内容。 gog gmail search 'from:boss newer_than:30d' --json gog gmail get --sanitize-content --json # 以 Gmail 网页 UI 可导入的格式导出 Gmail 过滤器。 gog gmail settings filters export --out filters.xml # 在自动化期间硬阻止发送操作。 gog --gmail-no-send gmail drafts create --to you@example.com --subject test ``` ### Calendar 文档: [`gog calendar`](docs/commands/gog-calendar.md), [`calendar create`](docs/commands/gog-calendar-create.md), [`calendar update`](docs/commands/gog-calendar-update.md), [`calendar move`](docs/commands/gog-calendar-move.md)。 ``` gog calendar events --today gog calendar create --summary "Review" \ --from "2026-05-06T10:00:00+02:00" \ --to "2026-05-06T10:30:00+02:00" gog calendar create primary --summary "Coffee" \ --from "2026-05-06T10:00:00+02:00" \ --to "2026-05-06T10:30:00+02:00" \ --location-search "Elysian Coffee Vancouver" gog calendar update primary --with-meet gog calendar move primary team-calendar@example.com gog calendar appointments ``` ### Drive 文档: [Drive 审计](docs/drive-audits.md), [原始 API 转储](docs/raw-api.md), [`gog drive`](docs/commands/gog-drive.md), [`drive changes`](docs/commands/gog-drive-changes.md), [`drive activity`](docs/commands/gog-drive-activity.md)。 ``` # 只读文件夹审计。 gog drive tree --parent --depth 2 gog drive du --parent --max 20 --json gog drive inventory --parent --json gog drive audit sharing --parent --internal-domain example.com --json gog drive labels list --json # Drive Labels 需要 Google Workspace 客户。 # 向 Drive 请求非默认字段。 gog drive get --fields 'id,name,mimeType,size,owners,emailAddress' --json # 跟踪更改和审计活动。 gog drive changes start-token gog drive changes list --token --json gog drive activity query --file --actions edit,share --from 2026-01-01T00:00:00Z --json # 无损原始 API JSON。 gog drive raw --pretty ``` ### Maps 文档: [`gog maps`](docs/commands/gog-maps.md), [`maps places`](docs/commands/gog-maps-places.md)。 ``` gog maps places search "Elysian Coffee Vancouver" --json gog maps places details --json ``` ### Photos 文档: [`gog photos`](docs/commands/gog-photos.md)。 ``` gog photos list --json gog photos search --media-type PHOTO --from 2026-01-01 --to 2026-01-31 --json gog photos download --out photo.jpg ``` ### Contacts 文档: [联系人去重](docs/contacts-dedupe.md), [JSON 联系人更新](docs/contacts-json-update.md), [`gog contacts`](docs/commands/gog-contacts.md)。 ``` gog contacts search alice --json gog contacts export --all --out contacts.vcf # 仅预览:不发起 merge/delete/update 调用。 gog contacts dedupe --json gog contacts dedupe --match email,phone,name --dry-run ``` ### Docs 文档: [Google Docs 编辑](docs/docs-editing.md), [sed 风格文档编辑](docs/sedmat.md), [`gog docs`](docs/commands/gog-docs.md)。 ``` gog docs write --append --markdown --text '## Status' gog docs format --match Status --bold --font-size 18 gog docs add-tab --title "Notes" gog docs find-replace old new --tab "Notes" --dry-run gog docs raw --pretty ``` ### Sheets 文档: [Sheets 表格](docs/sheets-tables.md), [Sheets 格式化](docs/sheets-formatting.md), [`gog sheets`](docs/commands/gog-sheets.md)。 ``` gog sheets get 'Sheet1!A1:D20' --json gog sheets table list gog sheets table append Tasks 'Ship README|done' gog sheets table clear Tasks gog sheets conditional-format add 'Sheet1!A2:A100' \ --type text-contains \ --expr blocked \ --format-json '{"backgroundColor":{"red":1,"green":0.84,"blue":0.84}}' gog sheets banding set 'Sheet1!A1:D100' ``` ### Slides 和 Forms 文档: [从 Markdown 生成 Slides](docs/slides-markdown.md), [模板替换](docs/slides-template-replacement.md), [`gog slides`](docs/commands/gog-slides.md), [`gog forms`](docs/commands/gog-forms.md)。 ``` gog slides create-from-markdown "Weekly update" --content-file slides.md gog slides insert-text "New text" gog forms update --quiz=true gog forms add-question --title "What is 2+2?" --type radio -o 1 -o 4 --correct 4 --points 1 gog forms publish gog forms responses list --json gog forms raw --pretty ``` ### YouTube 文档: [`gog youtube`](docs/commands/gog-youtube.md), [`youtube channels`](docs/commands/gog-youtube-channels.md), [`youtube videos`](docs/commands/gog-youtube-videos.md), [`youtube activities`](docs/commands/gog-youtube-activities.md)。 ``` gog config set youtube_api_key YOUR_API_KEY gog yt channels list --id UC_x5XG1OV2P6uZZ5FSM9Ttw --json gog yt videos list --chart mostPopular --region US --max 5 gog yt activities list --mine -a you@gmail.com ``` ### Analytics 和 Search Console 文档: [`gog analytics`](docs/commands/gog-analytics.md), [`analytics report`](docs/commands/gog-analytics-report.md), [`gog searchconsole`](docs/commands/gog-searchconsole.md), [`searchconsole query`](docs/commands/gog-searchconsole-query.md)。 ``` gog analytics accounts --all --json gog analytics report 123456789 --from 7daysAgo --to today --dimensions date,country --metrics activeUsers,sessions gog searchconsole sites gog searchconsole query sc-domain:example.com --from 2026-02-01 --to 2026-02-07 --dimensions query,page --filter query:contains:gog gog searchconsole sitemaps submit sc-domain:example.com https://example.com/sitemap.xml --force ``` ### 备份 文档: [备份](docs/backup.md), [`gog backup`](docs/commands/gog-backup.md)。 ``` gog backup init --repo ~/Backups/gog gog backup push --services gmail,calendar,contacts,drive gog backup verify gog backup export --gmail-format markdown --out ~/Exports/gog ``` 在运行广泛或无人值守的备份作业之前,请参阅 [docs/backup.md](docs/backup.md)。 ## 输出和自动化 文档: [安全配置文件](docs/safety-profiles.md), [`gog schema`](docs/commands/gog-schema.md), [`gog config no-send`](docs/commands/gog-config-no-send.md)。 使用 `--json` 获取结构化输出,使用 `--plain` 获取稳定的 TSV 输出。提示、进度和警告信息会输出到 stderr,因此 stdout 始终保持可解析状态。 ``` gog --json gmail search 'has:attachment newer_than:90d' --max 50 | jq -r '.threads[].id' gog --plain calendar events --today ``` 有用的全局标志: - `--account `:选择一个账号 - `--client `:选择一个已存储的 OAuth 客户端 - `--json`:JSON 格式的 stdout 输出 - `--plain`:稳定的可解析文本 stdout 输出 - `--wrap-untrusted`:在 JSON/原始输出中,为获取的纯文本字段包裹外部不受信任内容的标记,供 LLM/智能体使用 - `--dry-run`:在命令支持计划的情况下打印预期操作 - `--no-input`:直接失败而不是提示输入 - `--force`:确认破坏性操作 - `--enable-commands `:仅允许选定的命令路径 - `--disable-commands `:阻止选定的命令路径 - `--gmail-no-send`:阻止 Gmail 发送操作 对于编程智能体或 CI,建议使用: ``` gog --account you@gmail.com \ --enable-commands gmail.search,gmail.get,drive.ls,docs.cat \ --gmail-no-send \ --wrap-untrusted \ --json \ gmail search 'newer_than:7d' ``` 对于更严格的智能体部署,请构建或下载内置安全配置文件的二进制文件。 请参阅 [docs/safety-profiles.md](docs/safety-profiles.md)。 ## Auth 和账号 文档: [Auth 客户端](docs/auth-clients.md), [`gog auth`](docs/commands/gog-auth.md), [`auth add`](docs/commands/gog-auth-add.md), [`auth doctor`](docs/commands/gog-auth-doctor.md), [`auth service-account`](docs/commands/gog-auth-service-account.md)。 ### OAuth 客户端 只需存储一次 Desktop OAuth 客户端: ``` gog auth credentials ~/Downloads/client_secret_....json gog auth add you@gmail.com --services gmail,calendar,drive ``` 当不同的账号应使用不同的 Cloud 项目时,请使用命名客户端: ``` gog --client work auth credentials ~/Downloads/work-client.json gog --client work auth add you@company.com gog auth credentials list ``` 有关客户端选择规则、域名映射、远程 OAuth、直接访问令牌、ADC 和服务账号的详细信息,请参阅 [docs/auth-clients.md](docs/auth-clients.md)。 ### 账号选择 ``` gog auth list --check gog auth alias set work you@company.com gog --account work gmail search 'is:unread' export GOG_ACCOUNT=you@gmail.com gog calendar events --today ``` ### 密钥环后端 默认情况下,`gog` 会使用可用的最佳操作系统密钥环。对于无头或容器运行环境,请使用加密文件后端,并从当前 shell 或 secret 存储中注入 `GOG_KEYRING_PASSWORD`。 ``` gog auth keyring gog auth keyring file GOG_KEYRING_BACKEND=file GOG_KEYRING_PASSWORD=... gog auth list --check ``` 对于 systemd 服务、网关和编程智能体,请在服务或智能体进程本身上设置相同的变量。成功的 shell 检查并不意味着智能体子进程继承了 `GOG_KEYRING_PASSWORD`;请通过实际的智能体入口点使用 `gog auth doctor --check --no-input` 进行验证。 切勿提交 OAuth 客户端 JSON 文件、refresh token、服务账号密钥或文件密钥环密码。 ### Workspace 服务账号 Workspace 管理员可以配置全域委派,然后存储供用户模拟使用的服务账号密钥: ``` gog auth service-account set user@company.com --key ~/Downloads/service-account.json gog --account user@company.com auth status ``` 服务账号主要用于 Workspace Admin、Groups、Keep 和全域自动化。它们不能替代消费者 Gmail 账号的普通 OAuth。 ## 服务 文档: [命令索引](docs/commands/README.md), [Workspace Admin](docs/workspace-admin.md), [`gog auth services`](docs/commands/gog-auth-services.md)。 常见用户服务: - Gmail、Calendar、Drive、Docs、Sheets、Slides、Forms、Meet、Apps Script - Analytics 和 Search Console - Contacts、People、Tasks、Classroom - Workspace 账号的 Chat - 备份和本地实用命令 Workspace/管理员服务: - Admin Directory - Cloud Identity Groups - 带有全域委派的 Keep Admin Directory 包括从 CLI 创建 Workspace 用户: ``` gog --account admin@example.com admin users create ada@example.com \ --first-name Ada \ --last-name Lovelace \ --password 'TempPass123!' \ --change-password \ --ou /Engineering ``` 省略 `--password` 以生成临时密码。有关服务账号设置、用户清理、恢复字段、组织部门和群组示例,请参阅 [docs/workspace-admin.md](docs/workspace-admin.md)。 还包括 Workspace 组织部门: ``` gog --account admin@example.com admin orgunits list --type all gog --account admin@example.com admin orgunits create Engineering --parent / ``` 生成的服务作用域表: | 服务 | 用户 | API | 作用域 | 备注 | | --- | --- | --- | --- | --- | | gmail | 是 | Gmail API | `https://www.googleapis.com/auth/gmail.modify`
`https://www.googleapis.com/auth/gmail.settings.basic`
`https://www.googleapis.com/auth/gmail.settings.sharing` | | | calendar | 是 | Calendar API | `https://www.googleapis.com/auth/calendar` | | | chat | 是 | Chat API | `https://www.googleapis.com/auth/chat.spaces`
`https://www.googleapis.com/auth/chat.messages`
`https://www.googleapis.com/auth/chat.memberships`
`https://www.googleapis.com/auth/chat.users.readstate.readonly` | | | classroom | 是 | Classroom API | `https://www.googleapis.com/auth/classroom.courses`
`https://www.googleapis.com/auth/classroom.rosters`
`https://www.googleapis.com/auth/classroom.coursework.students`
`https://www.googleapis.com/auth/classroom.coursework.me`
`https://www.googleapis.com/auth/classroom.courseworkmaterials`
`https://www.googleapis.com/auth/classroom.announcements`
`https://www.googleapis.com/auth/classroom.topics`
`https://www.googleapis.com/auth/classroom.guardianlinks.students`
`https://www.googleapis.com/auth/classroom.profile.emails`
`https://www.googleapis.com/auth/classroom.profile.photos` | | | drive | 是 | Drive API | `https://www.googleapis.com/auth/drive` | | | driveactivity | 是 | Drive Activity API | `https://www.googleapis.com/auth/drive.activity.readonly` | 只读审计/活动作用域;使用 --services driveactivity 授权 | | drivelabels | 是 | Drive Labels API | `https://www.googleapis.com/auth/drive.labels.readonly` | 只读 Drive 标签 schema;使用 --services drivelabels 授权 | | docs | 是 | Docs API, Drive API | `https://www.googleapis.com/auth/drive`
`https://www.googleapis.com/auth/documents` | 通过 Drive 导出/复制/创建 | | slides | 是 | Slides API, Drive API | `https://www.googleapis.com/auth/drive`>`https://www.googleapis.com/auth/presentations` | 创建/编辑演示文稿 | | contacts | 是 | People API | `https://www.googleapis.com/auth/contacts`
`https://www.googleapis.com/auth/contacts.other.readonly`
`https://www.googleapis.com/auth/directory.readonly` | 联系人 + 其他联系人 + 目录 | | tasks | 是 | Tasks API | `https://www.googleapis.com/auth/tasks` | | | sheets | 是 | Sheets API, Drive API | `https://www.googleapis.com/auth/drive`
`https://www.googleapis.com/auth/spreadsheets` | 通过 Drive 导出 | | people | 是 | People API | `profile` | OIDC 个人资料作用域 | | forms | 是 | Forms API | `https://www.googleapis.com/auth/forms.body`
`https://www.googleapis.com/auth/forms.responses.readonly` | | | sites | 是 | Drive API | `https://www.googleapis.com/auth/drive` | 新版 Google Sites 作为 Drive 文件公开 | | meet | 是 | Meet REST API | `https://www.googleapis.com/auth/meetings.space.created`
`https://www.googleapis.com/auth/meetings.space.readonly`
`https://www.googleapis.com/auth/meetings.space.settings` | | | appscript | 是 | Apps Script API | `https://www.googleapis.com/auth/script.projects`
`https://www.googleapis.com/auth/script.deployments`
`https://www.googleapis.com/auth/script.processes` | | | analytics | 是 | Analytics Admin API, Analytics Data API | `https://www.googleapis.com/auth/analytics.readonly` | GA4 账号摘要 + 报告 | | searchconsole | 是 | Search Console API | `https://www.googleapis.com/auth/webmasters` | 搜索分析 + 站点地图管理 | | ads | 是 | Google Ads API | `https://www.googleapis.com/auth/adwords` | 仅限 OAuth 作用域 | | groups | 否 | Cloud Identity API | `https://www.googleapis.com/auth/cloud-identity.groups.readonly` | 仅限 Workspace | | keep | 否 | Keep API | `https://www.googleapis.com/auth/keep` | 仅限 Workspace;服务账号 (全域委派) | | admin | 否 | Admin SDK Directory API | `https://www.googleapis.com/auth/admin.directory.user`
`https://www.googleapis.com/auth/admin.directory.group`
`https://www.googleapis.com/auth/admin.directory.group.member` | 仅限 Workspace;需要带有全域委派的服务账号 | | youtube | 是 | YouTube Data API v3 | `https://www.googleapis.com/auth/youtube.readonly` | 大多数读取操作也可以仅使用 API key (config youtube_api_key 或 GOG_YOUTUBE_API_KEY) | | photos | 是 | Photos Library API | `https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata` | 在 Google Photos Library API 作用域更改后,仅限应用创建的只读媒体 | 使用以下命令重新生成该表: ``` go run scripts/gen-auth-services-md.go ``` ## 文档 - [概述](docs/index.md) — 渲染于 - [安装](docs/install.md) — - [快速开始](docs/quickstart.md) — - [命令索引](docs/commands/README.md) — - [Gmail 工作流](docs/gmail-workflows.md) — - [Gmail watch](docs/watch.md) — - [Drive 审计](docs/drive-audits.md) — - [Docs 编辑](docs/docs-editing.md) — - [Sheets 表格](docs/sheets-tables.md) 和 [Sheets 格式化](docs/sheets-formatting.md) - [安全配置文件](docs/safety-profiles.md) — 命令防护和内置安全二进制文件 - [Auth 客户端](docs/auth-clients.md) — OAuth 客户端、账号映射和服务账号 - [Workspace Admin](docs/workspace-admin.md) — Workspace 用户、组织部门和群组管理 - [备份](docs/backup.md) — 加密的 Google 账号备份 - [CHANGELOG.md](CHANGELOG.md):发布说明 每个命令都内置了帮助信息: ``` gog --help gog gmail --help gog drive inventory --help gog schema --json ``` ## 开发 ``` make tools make build make fmt make lint make test make ci ``` 生成的命令文档: ``` make docs-commands make docs-site open dist/docs-site/index.html ``` 实时的 Google API 冒烟测试为 opt-in(选择性加入): ``` scripts/live-test.sh --fast --account you@gmail.com GOG_IT_ACCOUNT=you@gmail.com go test -tags=integration ./internal/integration ``` 有关发布清单,请参阅 [docs/RELEASING.md](docs/RELEASING.md)。 ## 致谢 灵感来源于 Mario Zechner 最初的 Google CLI: - [gmcli](https://github.com/badlogic/gmcli) - [gccli](https://github.com/badlogic/gccli) - [gdcli](https://github.com/badlogic/gdcli) ## 许可证 MIT
标签:API安全, API客户端, ChatGPT插件, CLI, Docker, EVTX分析, Gmail, Google Calendar, Google Docs, Google Drive, Google Sheets, Google Workspace, JSON输出, OAuth 2.0, SaaS管理, Shell脚本, WiFi技术, 威胁情报, 安全防御评估, 开发者工具, 日志审计, 服务账号, 生产效率, 系统管理员, 终端, 编程代理, 脚本自动化, 请求拦截