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 停止傳送信箱更新通知 (週期毫秒) 的通知。請在這天之前再次呼叫 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

詳情請參閱授權指南

標籤篩選器動作

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

列舉
include 只針對與 labelId 相關的訊息變更訊息接收推播通知。
exclude 接收所有訊息變更時的推播通知 (與 labelId 相關的通知除外)。