在指定使用者信箱中設定或更新推播通知監控。
HTTP 要求
POST https://gmail.googleapis.com/gmail/v1/users/{userId}/watch
這個網址使用 gRPC 轉碼語法。
路徑參數
| 參數 | |
|---|---|
userId |
使用者的電子郵件地址。特殊值 |
要求主體
要求主體會包含結構如下的資料:
| JSON 表示法 |
|---|
{ "labelIds": [ string ], "labelFilterAction": enum ( |
| 欄位 | |
|---|---|
labelIds[] |
要限制通知的 labelId 清單。根據預設,如果未指定,系統會推送所有變更。如果指定此屬性,系統會根據此屬性判斷產生推播通知時必須使用的標籤。 |
labelFilterAction |
已指定 |
labelFilterBehavior |
已指定 |
topicName |
用於發布事件的 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 |
信箱目前記錄的 ID。 |
expiration |
Gmail 停止傳送信箱更新通知的時間 (以紀元毫秒為單位)。請在上述時間前再次呼叫 |
授權範圍
需要下列其中一種 OAuth 範圍:
https://mail.google.com/https://www.googleapis.com/auth/gmail.modifyhttps://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.metadata
詳情請參閱OAuth 2.0 Overview。
LabelFilterAction
指定 labelIds 清單的篩選行為。
| 列舉 | |
|---|---|
include |
只接收與指定 labelIds 相關的訊息異動推播通知。 |
exclude |
接收所有訊息異動的推播通知,但與指定 labelIds 相關的異動除外。 |