Method: users.watch
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
הגדרה או עדכון של מעקב אחר התראות בדחיפה בתיבת הדואר של המשתמש הנתון.
בקשת HTTP
POST https://gmail.googleapis.com/gmail/v1/users/{userId}/watch
כתובת ה-URL משתמשת בתחביר של Transcoding של 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 יפסיק לשלוח התראות על עדכונים בתיבת הדואר הנכנס (epoch millis). עליך להתקשר שוב למספר 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 שצוינה.
טיפוסים בני מנייה (enum) |
include |
קבלת התראות רק על שינויים בהודעות שקשורים למזהי התווית שצוינו. |
exclude |
קבלת התראות על כל השינויים בהודעה, מלבד שינויים שקשורים למזהי התווית שצוינו. |
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 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. |"]]