Method: users.watch
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
یک ساعت اعلان فشاری را در صندوق پستی کاربر مشخص شده تنظیم یا به روز کنید.
درخواست HTTP
POST https://gmail.googleapis.com/gmail/v1/users/{userId}/watch
URL از دستور GRPC Transcoding استفاده می کند.
پارامترهای مسیر
پارامترها |
---|
userId | string آدرس ایمیل کاربر. مقدار ویژه me می تواند برای نشان دادن کاربر تأیید شده استفاده شود. |
درخواست بدن
بدنه درخواست حاوی داده هایی با ساختار زیر است:
فیلدها |
---|
labelIds[] | string فهرست labelIds برای محدود کردن اعلانها. به طور پیش فرض، اگر مشخص نشده باشد، همه تغییرات حذف می شوند. اگر مشخص شده باشد، تعیین می کند که چه برچسب هایی برای ایجاد یک اعلان فشار لازم است. |
labelFilterAction (deprecated) | enum ( LabelFilterAction ) رفتار فیلتر کردن labelIds list مشخص شده است. این فیلد منسوخ شده است زیرا در برخی موارد باعث رفتار نادرست شده است. به جای آن از labelFilterBehavior استفاده کنید. |
labelFilterBehavior | enum ( LabelFilterAction ) رفتار فیلتر کردن labelIds list مشخص شده است. این فیلد جایگزین labelFilterAction می شود. اگر تنظیم شود، labelFilterAction نادیده گرفته می شود. |
topicName | string نام موضوع Google Cloud Pub/Sub API کاملاً واجد شرایط برای انتشار رویدادها. این نام موضوع باید قبلاً در Cloud Pub/Sub وجود داشته باشد و شما باید قبلاً مجوز "انتشار" به جیمیل را برای آن اعطا کرده باشید. به عنوان مثال، "projects/my-project-identifier/topics/my-topic-name" (با استفاده از قالب نامگذاری موضوع Cloud Pub/Sub "v1"). توجه داشته باشید که بخش «شناسه پروژه من» باید دقیقاً با شناسه پروژه توسعهدهنده 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 و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی."],[],[],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. |"]]