gog 是做什么的?
使用 gog 管理 Gmail/日历/云端硬盘/联系人/表格/文档。需要 OAuth 设置。
优先使用已授权的宿主账户:先运行所需的 gog 命令。仅在出现认证错误后才进行设置。切勿在聊天中索要密码、客户端密钥或刷新令牌。
设置(仅一次)
gog auth credentials /path/to/client_secret.jsongog auth add [email protected] --services gmail,calendar,drive,contacts,docs,sheetsgog auth list
远程/无头网关主机
当网关主机没有本地浏览器显示时:
- 优先在网关主机上使用实时回调侦听器。从带有浏览器的机器上,转发确切的回调端口(
ssh -L <port>:127.0.0.1:<port> user@gateway-host),打开gog打印的授权 URL,让重定向在转发的端口上完成。 - 当无法使用实时侦听器时,操作员在网关主机的受信任 shell 中选择一种粘贴模式路径。回调 URL 绝不能进入聊天或代理工具输入:
--manual:操作员将完整的重定向 URL 粘贴到gog的交互式提示中。--remote --step 1:打印auth_url(和state_reused)然后退出。浏览器授权后,操作员在受信任 shell 中运行--remote --step 2 --auth-url <callback-url>。同意后加载localhost页面失败是预期行为。
- 在远程步骤之间保持相同的已解析配置上下文:
GOG_CONFIG_DIR优先于--home,--home优先于GOG_HOME。同时保留--client、服务/作用域、重定向 URI 和同意选项。匹配且未过期的手动状态可被重用(state_reused=true)。 - 如果桌面密钥环不可用,请配置文件后端(
gog auth keyring file)并在网关环境中设置GOG_KEYRING_PASSWORD,以便非交互式代理/--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> - 日历列出事件:
gog calendar events <calendarId> --from <iso> --to <iso> - 日历创建事件:
gog calendar create <calendarId> --summary "Title" --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" --event-color 4 - 日历显示颜色:
gog calendar colors - 云端硬盘搜索:
gog drive search "query" --max 10 - 联系人:
gog contacts list --max 20 - 表格获取:
gog sheets get <sheetId> "Tab!A1:D10" --json - 表格更新:
gog sheets update <sheetId> "Tab!A1:B2" --values-json '[['"A"','"B"'],['"1"','"2"']]' --input USER_ENTERED - 表格追加:
gog sheets append <sheetId> "Tab!A:C" --values-json '[['"x"','"y"','"z"']]' --insert INSERT_ROWS - 表格清除:
gog sheets clear <sheetId> "Tab!A2:Z" - 表格元数据:
gog sheets metadata <sheetId> --json - 文档导出:
gog docs export <docId> --format txt --out /tmp/doc.txt - 文档查看:
gog docs cat <docId>
日历颜色
- 使用
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' 你好,姓名: 感谢今天的会议。下一步: - 事项一 - 事项二 此致 你的名字 EOF -
示例(HTML 列表):
gog gmail send --to [email protected] \ --subject "Meeting Follow-up" \ --body-html "<p>你好,姓名:</p><p>感谢今天的会议。以下是下一步:</p><ul><li>事项一</li><li>事项二</li></ul><p>此致,<br>你的名字</p>"
注意事项
- 设置
[email protected]以避免重复使用--account。 - 对于脚本化操作,优先使用
--json加--no-input。 - 表格值可以通过
--values-json(推荐)或内联行传递。 - 文档支持导出/查看/复制。原地编辑需要使用 Docs API 客户端(不在 gog 中)。
gog gmail search每线程返回一行;当需要单独返回每条邮件时,请使用gog gmail messages search。