Method: users.watch
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Konfigurowanie lub aktualizowanie powiadomień push w skrzynce pocztowej danego użytkownika.
Żądanie HTTP
POST https://gmail.googleapis.com/gmail/v1/users/{userId}/watch
Adres URL używa składni transkodowania gRPC.
Parametry ścieżki
Parametry |
userId |
string
Adres e-mail użytkownika. Wartość specjalna me może służyć do wskazywania uwierzytelnionego użytkownika.
|
Treść żądania
Treść żądania zawiera dane o następującej strukturze:
Pola |
labelIds[] |
string
Lista identyfikatorów etykiet, dla których mają być ograniczane powiadomienia. Domyślnie, jeśli nie określisz inaczej, wszystkie zmiany są przesyłane. Jeśli jest określony, określa, które etykiety są wymagane do wygenerowania powiadomienia push.
|
labelFilterAction (deprecated) |
enum (LabelFilterAction )
Określ działanie filtra labelIds list . To pole zostało wycofane, ponieważ w niektórych przypadkach powodowało nieprawidłowe działanie. Zamiast niego używaj pola labelFilterBehavior .
|
labelFilterBehavior |
enum (LabelFilterAction )
Określ działanie filtra labelIds list . To pole zastępuje pole labelFilterAction . Jeśli to pole jest ustawione, pole labelFilterAction jest ignorowane.
|
topicName |
string
W pełni kwalifikowana nazwa tematu interfejsu Google Cloud Pub/Sub API, w którym mają być publikowane zdarzenia. Ta nazwa tematu musi już istnieć w Cloud Pub/Sub, a Ty musisz mieć już przyznane uprawnienia „publikowania” dla usługi Gmail. Na przykład „projekty/identyfikator_projektu/tematy/nazwa_tematu” (w formacie nazewnictwa tematów w Cloud Pub/Sub w wersji „1”). Pamiętaj, że część „my-project-identifier” musi dokładnie odpowiadać identyfikatorowi Twojego projektu dewelopera Google (identyfikatorowi, który wykonuje to żądanie monitorowania).
|
Treść odpowiedzi
Odpowiedź na powiadomienie push na zegarku.
W przypadku powodzenia treść żądania zawiera dane o następującej strukturze:
Zapis JSON |
{
"historyId": string,
"expiration": string
} |
Pola |
historyId |
string
Identyfikator bieżącego rekordu historii skrzynki pocztowej.
|
expiration |
string (int64 format)
Kiedy Gmail przestanie wysyłać powiadomienia o zmianach w skrzynce pocztowej (w milisekundach ery) Aby odnowić subskrypcję zegarka, zadzwoń ponownie na numer watch przed upływem tego czasu.
|
Zakresy autoryzacji
Wymaga jednego z tych zakresów 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
Więcej informacji znajdziesz w przewodniku dotyczącym autoryzacji.
LabelFilterAction
Sposób filtrowania listy etykiet (labelIds)
Wartości w polu enum |
include |
otrzymywać powiadomienia push tylko w przypadku zmian wiadomości związanych z określonymi identyfikatorami etykiet. |
exclude |
Otrzymywać powiadomienia push o wszystkich zmianach wiadomości z wyjątkiem tych dotyczących określonych identyfikatorów etykiet. |
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-25 UTC.
[null,null,["Ostatnia aktualizacja: 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. |"]]