Method: users.watch
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
지정된 사용자 메일함에서 푸시 알림 보기를 설정하거나 업데이트합니다.
HTTP 요청
POST https://gmail.googleapis.com/gmail/v1/users/{userId}/watch
URL은 gRPC 트랜스코딩 문법을 사용합니다.
경로 매개변수
매개변수 |
userId |
string
사용자의 이메일 주소 인증된 사용자를 나타내는 데 특수 값 me 을 사용할 수 있습니다.
|
요청 본문
요청 본문에는 다음과 같은 구조의 데이터가 포함됩니다.
필드 |
labelIds[] |
string
알림을 제한할 labelId 목록입니다. 지정하지 않으면 기본적으로 모든 변경사항이 푸시됩니다. 지정된 경우 푸시 알림을 생성하는 데 필요한 라벨을 지정합니다.
|
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
열거형 |
include |
지정된 labelId와 관련된 메시지 변경사항에 대한 푸시 알림만 받습니다. |
exclude |
지정된 labelIds와 관련된 변경사항을 제외한 모든 메시지 변경사항에 대한 푸시 알림을 받습니다. |
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 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. |"]]