Files
nexus/wiki/syntheses/GOG-CLI工具.md

71 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: GOG CLI 工具
type: synthesis
tags: [Google Workspace, CLI工具, Gmail, Calendar, Drive]
sources: []
last_updated: 2026-04-15
---
## 概述
GOG CLIGoogle Workspace CLI是由 steipete 开发的 macOS/Linux 命令行工具,通过 OAuth 为 Gmail、Google Calendar、Google Drive、Google Contacts、Google Sheets、Google Docs 提供命令行接口。
## 支持的 Google 服务
| 服务 | 支持功能 |
|------|---------|
| **Gmail** | 搜索threads/messages、发送普通/HTML/回复)、草稿创建与发送 |
| **Calendar** | 列表、创建、更新事件支持颜色标记11色 |
| **Drive** | 文件搜索 |
| **Contacts** | 联系人列表 |
| **Sheets** | 读取、更新、追加、清除、元数据查询 |
| **Docs** | 导出txt、读取内容cat |
## 认证方式
1. 通过 `gog auth credentials /path/to/client_secret.json` 配置 OAuth 客户端
2. 通过 `gog auth add <email> --services gmail,calendar,drive,contacts,docs,sheets` 授权所需服务
3. 支持多账户:`--account <email>` 参数切换
## 核心命令示例
### Gmail
```bash
gog gmail search 'newer_than:7d' --max 10
gog gmail messages search "in:inbox from:ryanair.com" --max 20 --account you@example.com
gog gmail send --to a@b.com --subject "Hi" --body-file ./message.txt
```
### Calendar
```bash
gog calendar events <calendarId> --from <iso> --to <iso>
gog calendar create <calendarId> --summary "Title" --from <iso> --to <iso> --event-color 7
gog calendar update <calendarId> <eventId> --summary "New Title"
gog calendar colors # 查看可用颜色
```
### Sheets
```bash
gog sheets get <sheetId> "Tab!A1:D10" --json
gog sheets update <sheetId> "Tab!A1:B2" --values-json '[["A","B"],["1","2"]]'
gog sheets append <sheetId> "Tab!A:C" --values-json '[["x","y","z"]]'
```
### Docs
```bash
gog docs export <docId> --format txt --out /tmp/doc.txt
gog docs cat <docId>
```
## 环境变量
- `GOG_ACCOUNT=you@gmail.com` — 避免每次重复 `--account` 参数
## 注意事项
- 发送邮件或创建事件前需二次确认
- Sheets 值传递推荐使用 `--values-json`
- `--body` 参数不解析 `\n`,多行内容需用 `--body-file`
- Docs 不支持原地编辑,需通过 Docs API 客户端实现
## 安装
```bash
brew install steipete/tap/gogcli
```