Method: users.watch
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
指定したユーザーのメールボックスでプッシュ通知ウォッチを設定または更新します。
HTTP リクエスト
POST https://gmail.googleapis.com/gmail/v1/users/{userId}/watch
この URL は gRPC Transcoding 構文を使用します。
パスパラメータ
パラメータ |
userId |
string
ユーザーのメールアドレスです。認証されたユーザーを示すには、特別な値 me を使用できます。
|
リクエストの本文
リクエストの本文には、次の構造のデータが含まれます。
フィールド |
labelIds[] |
string
通知を制限する labelId のリスト。デフォルトでは、指定しない場合、すべての変更が push されます。指定すると、プッシュ通知の生成に必要なラベルを指定します。
|
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 デベロッパー プロジェクト ID(このウォッチ リクエストを実行するプロジェクト ID)と完全に一致している必要があります。
|
レスポンスの本文
プッシュ通知のスマートウォッチでの応答。
成功した場合、レスポンスの本文には次の構造のデータが含まれます。
JSON 表現 |
{
"historyId": string,
"expiration": string
} |
フィールド |
historyId |
string
メールボックスの現在の履歴レコードの ID。
|
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 リストのフィルタ動作。
列挙型 |
include |
指定された labelId に関連するメッセージの変更に関するプッシュ通知のみを受信します。 |
exclude |
指定された labelId に関連するものを除く、すべてのメッセージ変更に関するプッシュ通知を受け取ります。 |
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 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. |"]]