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
遠端 / 無頭(headless)閘道主機
當閘道主機沒有本機瀏覽器顯示時:
- 優先使用閘道主機上的即時回調監聽器。從有瀏覽器的機器上,轉發確切的回調埠(
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,後者優先於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' 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(建議)或作為內聯行傳遞。 - 文件支援匯出/顯示/複製。就地編輯需要 Docs API 客戶端(不在 gog 中)。
gog gmail search每個會話回傳一行;當你需要分別回傳每個個別電子郵件時,請使用gog gmail messages search。