关于 gog
gog 是用于 Google 邮件、日历、云端硬盘、联系人、表格和文档的命令行工具,适合通过命令处理这些服务的个人与自动化流程。它支持 OAuth,并提供无浏览器主机上的远程授权步骤。
主要功能
- 01搜索、发送和管理 Gmail 邮件
- 02列出及创建日历活动
- 03搜索和读取 Drive 文件
- 04管理联系人与 Sheets 数据
- 05导出及查看 Docs 文档
- 06支持远程 OAuth 授权
适用场景
- 01查找近期邮件并发送回复
- 02创建日历活动并设置颜色
- 03搜索 Drive 文件或读取表格范围
- 04在无本地浏览器的主机上完成授权
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ openclaw/ openclaw --skill gog安装后在 Claude Code 中输入/gog确认已加载。
详细介绍
gog
使用 gog 管理 Gmail/Calendar/Drive/Contacts/Sheets/Docs。需要进行 OAuth 设置。
优先使用主机上已完成授权的账户:先运行所请求的 gog 命令。仅在发生身份验证错误后进入设置。切勿在聊天中索要密码、客户端密钥或刷新令牌。
设置(只需一次)
gog auth credentials /path/to/client_secret.jsongog auth add [email protected] --services gmail,calendar,drive,contacts,docs,sheetsgog auth list
远程/无头 Gateway 主机
当 Gateway 主机没有本地浏览器显示时:
- 优先在 Gateway 主机上使用实时回调监听器。在带浏览器的机器上,转发确切的回调端口(
ssh -L <port>:127.0.0.1:<port> user@gateway-host),打开gog输出的授权 URL,并让重定向在该转发端口上完成。 - 无法使用实时监听器时,操作员应在 Gateway 主机上受信任的命令行环境中选择一种粘贴模式流程。回调 URL 绝不能出现在聊天或 Agent 工具输入中:
--manual:操作员将完整的重定向 URL 粘贴到gog的交互式提示中。--remote --step 1:输出auth_url(以及state_reused)后退出。浏览器同意授权后,操作员在受信任的命令行环境中运行--remote --step 2 --auth-url <callback-url>。同意授权后出现localhost页面加载失败属于预期情况。
- 在各远程步骤之间保持相同的已解析配置上下文:
GOG_CONFIG_DIR优先于--home,后者又优先于GOG_HOME。同时保留--client、服务/范围、重定向 URI 和同意选项。匹配的未过期手动状态可能会被复用(state_reused=true)。 - 如果桌面密钥环不可用,请配置文件后端(
gog auth keyring file),并在 Gateway 环境中设置GOG_KEYRING_PASSWORD,以便非交互式 Agent/--no-input运行能够读取令牌。缺少密码时,gog auth doctor会报告该情况。 - 收到回调并不表示令牌已存储。如果令牌交换或身份查询在代理后失败,请在操作员批准针对所需 Google 端点的受限出站访问或代理例外后,从步骤 1 重新开始。不得绕过主机网络策略,也不得复用失败或过期的状态。
进行诊断时,应检查 gog auth list --check 报告的每个条目;其退出状态不能证明所有已存储令牌都有效。同样,应检查 gog auth doctor 报告的状态,而不是仅依赖其退出代码。
常用命令
- Gmail 搜索:
gog gmail search 'newer_than:7d' --max 10 - Gmail 消息搜索(逐封邮件,忽略会话线程):
gog gmail messages search "in:inbox from:ryanair.com" --max 20 --account [email protected] - Gmail 发送(纯文本):
gog gmail send --to [email protected] --subject "Hi" --body "Hello" - Gmail 发送(多行):
gog gmail send --to [email protected] --subject "Hi" --body-file ./message.txt - Gmail 发送(标准输入):
gog gmail send --to [email protected] --subject "Hi" --body-file - - Gmail 发送(HTML):
gog gmail send --to [email protected] --subject "Hi" --body-html "<p>Hello</p>" - Gmail 草稿:
gog gmail drafts create --to [email protected] --subject "Hi" --body-file ./message.txt - Gmail 发送草稿:
gog gmail drafts send <draftId> - Gmail 回复:
gog gmail send --to [email protected] --subject "Re: Hi" --body "Reply" --reply-to-message-id <msgId> - Calendar 列出日程:
gog calendar events <calendarId> --from <iso> --to <iso> - Calendar 创建日程:
gog calendar create <calendarId> --summary "Title" --from <iso> --to <iso> - Calendar 创建带颜色的日程:
gog calendar create <calendarId> --summary "Title" --from <iso> --to <iso> --event-color 7 - Calendar 更新日程:
gog calendar update <calendarId> <eventId> --summary "New Title" --event-color 4 - Calendar 显示颜色:
gog calendar colors - Drive 搜索:
gog drive search "query" --max 10 - Contacts:
gog contacts list --max 20 - Sheets 获取:
gog sheets get <sheetId> "Tab!A1:D10" --json - Sheets 更新:
gog sheets update <sheetId> "Tab!A1:B2" --values-json '[["A","B"],["1","2"]]' --input USER_ENTERED - Sheets 追加:
gog sheets append <sheetId> "Tab!A:C" --values-json '[["x","y","z"]]' --insert INSERT_ROWS - Sheets 清除:
gog sheets clear <sheetId> "Tab!A2:Z" - Sheets 元数据:
gog sheets metadata <sheetId> --json - Docs 导出:
gog docs export <docId> --format txt --out /tmp/doc.txt - Docs 查看内容:
gog docs cat <docId>
Calendar 颜色
- 使用
gog calendar colors查看所有可用的日程颜色(ID 1-11) - 使用
--event-color <id>标志为日程添加颜色 - 日程颜色 ID(来自
gog calendar colors的输出):- 1: #a4bdfc
- 2: #7ae7bf
- 3: #dbadff
- 4: #ff887c
- 5: #fbd75b
- 6: #ffb878
- 7: #46d6db
- 8: #e1e1e1
- 9: #5484ed
- 10: #51b749
- 11: #dc2127
电子邮件格式
-
优先使用纯文本。多段落邮件请使用
--body-file(或使用--body-file -从标准输入读取)。 -
草稿和回复也支持相同的
--body-file模式。 -
--body不会对\n进行反转义处理。如果需要内嵌换行符,请使用 heredoc 或$'Line 1\n\nLine 2'。 -
仅在需要丰富格式时使用
--body-html。 -
HTML 标签:段落使用
<p>,换行使用<br>,粗体使用<strong>,斜体使用<em>,链接使用<a href="url">,列表使用<ul>/<li>。 -
示例(通过标准输入使用纯文本):
gog gmail send --to [email protected] \ --subject "Meeting Follow-up" \ --body-file - <<'EOF' Hi Name, Thanks for meeting today. Next steps: - Item one - Item two Best regards, Your Name EOF -
示例(HTML 列表):
gog gmail send --to [email protected] \ --subject "Meeting Follow-up" \ --body-html "<p>Hi Name,</p><p>Thanks for meeting today. Here are the next steps:</p><ul><li>Item one</li><li>Item two</li></ul><p>Best regards,<br>Your Name</p>"
注意
- 设置
[email protected],避免重复使用--account。 - 编写脚本时,优先使用
--json和--no-input。 - 可通过
--values-json(推荐)或内联行形式传递 Sheets 值。 - Docs 支持 export/cat/copy。原地编辑需要 Docs API 客户端(gog 中不提供)。
gog gmail search每个会话线程返回一行;需要分别返回每一封邮件时,请使用gog gmail messages search。
评论
支持 Markdown