Method: users.watch
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Belirtilen kullanıcı posta kutusunda push bildirimi izleme ayarını oluşturun veya güncelleyin.
HTTP isteği
POST https://gmail.googleapis.com/gmail/v1/users/{userId}/watch
URL, gRPC Kod Dönüştürme söz dizimini kullanır.
Yol parametreleri
Parametreler |
userId |
string
Kullanıcının e-posta adresi. Kimliği doğrulanmış kullanıcıyı belirtmek için me özel değeri kullanılabilir.
|
İstek içeriği
İstek metni aşağıdaki yapıyla birlikte verileri içerir:
Alanlar |
labelIds[] |
string
Bildirimleri kısıtlanacak labelId'lerin listesi. Belirtilmemişse varsayılan olarak tüm değişiklikler yayınlanır. Belirtilirse bir push bildiriminin oluşturulması için hangi etiketlerin gerekli olduğunu belirtir.
|
labelFilterAction (deprecated) |
enum (LabelFilterAction )
labelIds list için filtreleme davranışı belirtilmiş. Bazı durumlarda yanlış davranışa neden olduğu için bu alanın desteği sonlandırıldı. Bunun yerine labelFilterBehavior kullanın.
|
labelFilterBehavior |
enum (LabelFilterAction )
labelIds list için filtreleme davranışı belirtilmiş. Bu alan labelFilterAction alanının yerini alır. Ayarlanırsa labelFilterAction yoksayılır.
|
topicName |
string
Etkinliklerin yayınlanacağı tam nitelikli Google Cloud Pub/Sub API konu adı. Bu konu adı Cloud Pub/Sub'da mevcut olmalıdır ve gmail için "yayınlama" iznini vermiş olmanız gerekir. Örneğin, "projects/proje-tanımlayıcım/konular/konu-adım" (Cloud Pub/Sub "v1" konu adlandırma biçimi kullanılarak). "my-project-identifier" kısmının, Google geliştirici proje kimliğinizle (bu izleme isteğini yürüten) tam olarak eşleşmesi gerektiğini unutmayın.
|
Yanıt gövdesi
Push bildirimi izleme yanıtı.
Başarılı olursa yanıt metni aşağıdaki yapıyla birlikte verileri içerir:
JSON gösterimi |
{
"historyId": string,
"expiration": string
} |
Alanlar |
historyId |
string
Posta kutusunun mevcut geçmiş kaydının kimliği.
|
expiration |
string (int64 format)
Gmail'in posta kutusu güncellemeleri için bildirim göndermeyi durduracağı zaman (milisaniye cinsinden başlangıç zamanı). Kol saatini yenilemek için bu tarihten önce watch numaralı telefonu tekrar arayın.
|
Yetkilendirme kapsamları
Aşağıdaki OAuth kapsamlarından birini gerektirir:
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
Daha fazla bilgi için Yetkilendirme kılavuzuna bakın.
LabelFilterAction
labelIds listesinin filtreleme davranışı belirtilir.
Sıralamalar |
include |
Yalnızca belirtilen labelId'lerle ilgili ileti değişiklikleri için push bildirimi alın. |
exclude |
Belirtilen labelId'lerle ilgili olanlar hariç tüm mesaj değişiklikleri için push bildirimleri alın. |
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-07-25 UTC.
[null,null,["Son güncelleme tarihi: 2025-07-25 UTC."],[],[],null,["# Method: users.watch\n\n- [HTTP request](#body.HTTP_TEMPLATE)\n- [Path parameters](#body.PATH_PARAMETERS)\n- [Request body](#body.request_body)\n - [JSON representation](#body.request_body.SCHEMA_REPRESENTATION)\n- [Response body](#body.response_body)\n - [JSON representation](#body.WatchResponse.SCHEMA_REPRESENTATION)\n- [Authorization scopes](#body.aspect)\n- [LabelFilterAction](#LabelFilterAction)\n\nSet up or update a push notification watch on the given user mailbox.\n\n### HTTP request\n\n`POST https://gmail.googleapis.com/gmail/v1/users/{userId}/watch`\n\nThe URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.\n\n### Path parameters\n\n| Parameters ||\n|----------|-----------------------------------------------------------------------------------------------------------|\n| `userId` | `string` The user's email address. The special value `me` can be used to indicate the authenticated user. |\n\n### Request body\n\nThe request body contains data with the following structure:\n\n| JSON representation |\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"labelIds\": [ string ], \"labelFilterAction\": enum (/workspace/gmail/api/reference/rest/v1/users/watch#LabelFilterAction), \"labelFilterBehavior\": enum (/workspace/gmail/api/reference/rest/v1/users/watch#LabelFilterAction), \"topicName\": string } ``` |\n\n| Fields ||\n|--------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `labelIds[]` | `string` List of labelIds to restrict notifications about. By default, if unspecified, all changes are pushed out. If specified then dictates which labels are required for a push notification to be generated. |\n| `labelFilterAction` **(deprecated)** | `enum (`[LabelFilterAction](/workspace/gmail/api/reference/rest/v1/users/watch#LabelFilterAction)`)` Filtering behavior of `labelIds list` specified. This field is deprecated because it caused incorrect behavior in some cases; use `labelFilterBehavior` instead. |\n| `labelFilterBehavior` | `enum (`[LabelFilterAction](/workspace/gmail/api/reference/rest/v1/users/watch#LabelFilterAction)`)` Filtering behavior of `labelIds list` specified. This field replaces `labelFilterAction`; if set, `labelFilterAction` is ignored. |\n| `topicName` | `string` A fully qualified Google Cloud Pub/Sub API topic name to publish the events to. This topic name **must** already exist in Cloud Pub/Sub and you **must** have already granted gmail \"publish\" permission on it. For example, \"projects/my-project-identifier/topics/my-topic-name\" (using the Cloud Pub/Sub \"v1\" topic naming format). Note that the \"my-project-identifier\" portion must exactly match your Google developer project id (the one executing this watch request). |\n\n### Response body\n\nPush notification watch response.\n\nIf successful, the response body contains data with the following structure:\n\n| JSON representation |\n|-------------------------------------------------------|\n| ``` { \"historyId\": string, \"expiration\": string } ``` |\n\n| Fields ||\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `historyId` | `string` The ID of the mailbox's current history record. |\n| `expiration` | `string (`[int64](https://developers.google.com/discovery/v1/type-format)` format)` When Gmail will stop sending notifications for mailbox updates (epoch millis). Call `watch` again before this time to renew the watch. |\n\n### Authorization scopes\n\nRequires one of the following OAuth scopes:\n\n- `https://mail.google.com/`\n- `\n https://www.googleapis.com/auth/gmail.modify`\n- `\n https://www.googleapis.com/auth/gmail.readonly`\n- `\n https://www.googleapis.com/auth/gmail.metadata`\n\nFor more information, see the [Authorization guide](/workspace/guides/configure-oauth-consent).\n\nLabelFilterAction\n-----------------\n\nFiltering behavior of labelIds list specified.\n\n| Enums ||\n|-----------|---------------------------------------------------------------------------------------------|\n| `include` | Only get push notifications for message changes relating to labelIds specified. |\n| `exclude` | Get push notifications for all message changes except those relating to labelIds specified. |"]]