Method: users.watch

設定或更新指定使用者信箱的推播通知手錶。

HTTP 要求

POST https://gmail.googleapis.com/gmail/v1/users/{userId}/watch

這個網址使用 gRPC 轉碼語法。

路徑參數

參數
userId

string

使用者的電子郵件地址。特殊值 me 可用於表示已驗證使用者。

要求主體

要求主體的資料會採用以下結構:

JSON 表示法
{
  "labelIds": [
    string
  ],
  "labelFilterAction": enum (LabelFilterAction),
  "labelFilterBehavior": enum (LabelFilterAction),
  "topicName": string
}
欄位
labelIds[]

string

要限制相關通知的 labelId 清單。根據預設,如未指定,系統將推送所有變更。如果指定此屬性,就會指定要產生推播通知所需的標籤。

labelFilterAction
(deprecated)

enum (LabelFilterAction)

已指定 labelIds list 的篩選行為。這個欄位在某些情況下會導致錯誤行為,因此已遭淘汰;請改用 labelFilterBehavior

labelFilterBehavior

enum (LabelFilterAction)

已指定 labelIds list 的篩選行為。這個欄位會取代 labelFilterAction;如果已設定,則系統會忽略 labelFilterAction

topicName

string

要發布事件的完整 Google Cloud Pub/Sub API 主題名稱。這個主題名稱必須已存在於 Cloud Pub/Sub 中,且您必須已授予 Gmail 的「發布」權限。例如「projects/my-project-identifier/topics/my-topic-name」(使用 Cloud Pub/Sub「v1」主題命名格式)。

請注意,「my-project-identifier」部分必須與您的 Google 開發人員專案 ID (執行此手錶要求的 ID) 完全相符。

回應主體

推播通知監控工具回應。

如果成功,回應主體即會包含具有以下結構的資料:

JSON 表示法
{
  "historyId": string,
  "expiration": string
}
欄位
historyId

string

信箱目前記錄的 ID。

expiration

string (int64 format)

Gmail 何時停止傳送信箱更新通知 (Epoch 紀元時間)。請在這段時間內再次呼叫 watch,即可續訂智慧手錶。

授權範圍

需要下列其中一種 OAuth 範圍:

  • https://mail.google.com/
  • https://www.googleapis.com/auth/gmail.modify
  • https://www.googleapis.com/auth/gmail.readonly
  • https://www.googleapis.com/auth/gmail.metadata

詳情請參閱授權指南

LabelFilterAction

已指定 labelIds 清單的篩選行為。

列舉
include 只接收與指定 labelId 相關的郵件變更推播通知。
exclude 接收所有與指定 labelId 相關的訊息變更的推播通知。