Method: users.watch
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
दिए गए उपयोगकर्ता के मेलबॉक्स पर, पुश नोटिफ़िकेशन वॉच सेट अप या अपडेट करें.
एचटीटीपी अनुरोध
POST https://gmail.googleapis.com/gmail/v1/users/{userId}/watch
यूआरएल में gRPC ट्रांसकोडिंग सिंटैक्स का इस्तेमाल किया गया है.
पाथ पैरामीटर
पैरामीटर |
userId |
string
उपयोगकर्ता का ईमेल पता. पुष्टि किए गए उपयोगकर्ता की जानकारी देने के लिए, खास वैल्यू me का इस्तेमाल किया जा सकता है.
|
अनुरोध का मुख्य भाग
अनुरोध के मुख्य भाग में नीचे दिए गए स्ट्रक्चर वाला डेटा होता है:
फ़ील्ड |
labelIds[] |
string
जिन लेबल आईडी के लिए सूचनाओं पर पाबंदी लगानी है उनकी सूची. अगर कोई जानकारी नहीं दी जाती है, तो डिफ़ॉल्ट रूप से सभी बदलावों को पॉइंट किया जाता है. अगर यह पैरामीटर तय किया गया है, तो यह तय करता है कि पुश नोटिफ़िकेशन जनरेट करने के लिए कौनसे लेबल ज़रूरी हैं.
|
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 डेवलपर प्रोजेक्ट आईडी से पूरी तरह मेल खाना चाहिए. यह वह आईडी होता है जिससे स्मार्टवॉच के लिए अनुरोध किया जा रहा है.
|
जवाब का मुख्य भाग
स्मार्टवॉच पर पुश नोटिफ़िकेशन का जवाब.
अगर एपीआई सही से जुड़ जाता है, ताे जवाब के मुख्य भाग में नीचे दिए गए स्ट्रक्चर शामिल होता है.
JSON के काेड में दिखाना |
{
"historyId": string,
"expiration": string
} |
फ़ील्ड |
historyId |
string
मेलबॉक्स के मौजूदा इतिहास रिकॉर्ड का आईडी.
|
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
ज़्यादा जानकारी के लिए, अनुमति से जुड़ी गाइड देखें.
LabelFilterAction
दी गई labelIds सूची को फ़िल्टर करने का तरीका.
Enums |
include |
सिर्फ़ उन मैसेज में हुए बदलावों के लिए पुश नोटिफ़िकेशन पाएं जिनमें दिए गए labelIds शामिल हैं. |
exclude |
मैसेज में किए गए सभी बदलावों के लिए पुश नोटिफ़िकेशन पाएं. हालांकि, इनमें उन बदलावों के लिए सूचनाएं नहीं मिलेंगी जिनमें दिए गए labelIds शामिल हैं. |
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-07-25 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 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. |"]]