Method: users.watch
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Configura o aggiorna un orologio con notifiche push nella casella di posta dell'utente specificato.
Richiesta HTTP
POST https://gmail.googleapis.com/gmail/v1/users/{userId}/watch
L'URL utilizza la sintassi di transcodifica gRPC.
Parametri del percorso
Parametri |
userId |
string
L'indirizzo email dell'utente. Il valore speciale me può essere utilizzato per indicare l'utente autenticato.
|
Corpo della richiesta
Il corpo della richiesta contiene dati con la seguente struttura:
Campi |
labelIds[] |
string
Elenco di labelId per i quali limitare le notifiche. Per impostazione predefinita, se non specificato, tutte le modifiche vengono applicate. Se specificato, indica quali etichette sono necessarie per la generazione di una notifica push.
|
labelFilterAction (deprecated) |
enum (LabelFilterAction )
È stato specificato il comportamento di filtro di labelIds list . Questo campo è deprecato perché in alcuni casi causava un comportamento errato. Utilizza labelFilterBehavior .
|
labelFilterBehavior |
enum (LabelFilterAction )
È stato specificato il comportamento di filtro di labelIds list . Questo campo sostituisce labelFilterAction ; se impostato, labelFilterAction viene ignorato.
|
topicName |
string
Un nome di argomento API Google Cloud Pub/Sub completo a cui pubblicare gli eventi. Il nome dell'argomento deve già esistere in Cloud Pub/Sub e devi aver già concesso a Gmail l'autorizzazione di "pubblicazione". Ad esempio, "projects/my-project-identifier/topics/my-topic-name" (utilizzando il formato di denominazione degli argomenti Cloud Pub/Sub "v1"). Tieni presente che la parte "my-project-identifier" deve corrispondere esattamente all'ID progetto sviluppatore Google (quello che esegue questa richiesta di visualizzazione).
|
Corpo della risposta
Risposta alle notifiche push sullo smartwatch.
In caso di esito positivo, il corpo della risposta contiene dati con la seguente struttura:
Rappresentazione JSON |
{
"historyId": string,
"expiration": string
} |
Campi |
historyId |
string
L'ID del record della cronologia corrente della cassetta di posta.
|
expiration |
string (int64 format)
Quando Gmail smetterà di inviare notifiche per gli aggiornamenti della cassetta di posta (epoch millis). Chiama di nuovo il numero watch prima di questa ora per rinnovare lo smartwatch.
|
Ambiti di autorizzazione
Richiede uno dei seguenti ambiti 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
Per ulteriori informazioni, consulta la Guida all'autorizzazione.
LabelFilterAction
Comportamento di filtro dell'elenco labelIds specificato.
Enum |
include |
Ricevere notifiche push solo per le modifiche ai messaggi relative agli ID etichetta specificati. |
exclude |
Ricevi notifiche push per tutte le modifiche ai messaggi, ad eccezione di quelle relative agli ID etichetta specificati. |
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-25 UTC.
[null,null,["Ultimo aggiornamento 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. |"]]