Google Workspace 구독 업데이트 또는 갱신하기
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이 페이지에서는 subscriptions.update()
메서드를 사용하여 Google Workspace 구독을 갱신하는 방법을 설명합니다. 이 메서드를 사용하여 구독의 만료 시간을 업데이트할 수 있습니다. 여기에는 가능한 최대 만료 시간으로 구독을 갱신하거나 타겟 리소스에 관해 수신할 이벤트 유형 목록을 업데이트하는 것이 포함됩니다.
Python
- Python 3.6 이상
- pip 패키지 관리 도구
- 최신 Python용 Google 클라이언트 라이브러리 이를 설치하거나 업데이트하려면 명령줄 인터페이스에서 다음 명령어를 실행하세요.
pip3 install --upgrade google-api-python-client google-auth-oauthlib
Google Workspace 구독 갱신하기
이 섹션에서는 Google Workspace Events API의 subscriptions.update()
메서드를 사용하여 구독을 최대 만료 시간으로 갱신합니다. 최대 만료 시간을 지정하려면 Subscription
리소스의 ttl
필드를 0
로 업데이트합니다.
최대 만료 시간은 이벤트 페이로드에 포함된 리소스 데이터에 따라 다릅니다. 만료 시간에 대해 자세히 알아보려면 Google Workspace 이벤트의 이벤트 데이터를 참고하세요.
Google Workspace 구독을 갱신하려면 다음 단계를 따르세요.
Apps Script
Apps Script 프로젝트에서 updateSubscription
라는 새 스크립트 파일을 만들고 다음 코드를 추가합니다.
function updateSubscription() {
// The name of the subscription to update.
const name = 'subscriptions/SUBSCRIPTION_ID';
// Call the Workspace Events API using the advanced service.
const response = WorkspaceEvents.Subscriptions.patch({
ttl: '0s',
}, name);
console.log(response);
}
다음을 바꿉니다.
SUBSCRIPTION_ID
: 정기 결제의 ID입니다. ID를 가져오려면 다음 중 하나를 사용하세요.
-
uid
필드의 값입니다.
-
name
필드에 표시된 리소스 이름의 ID입니다. 예를 들어 리소스 이름이 subscriptions/subscription-123
이면 subscription-123
을 사용합니다.
Google Workspace 구독을 업데이트하려면 Apps Script 프로젝트에서 updateSubscription
함수를 실행하세요.
Python
작업 디렉터리에서 update_subscription.py
라는 파일을 만들고 다음 코드를 추가합니다.
"""Update subscription."""
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
# Specify required scopes.
SCOPES = [SCOPES]
# Authenticate with Google Workspace and get user authentication.
flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
CREDENTIALS = flow.run_local_server()
# Call the Workspace Events API using the service endpoint.
service = build(
'workspaceevents',
'v1',
credentials=CREDENTIALS,
)
BODY = {
'ttl': {'seconds': 0},
}
NAME = 'subscriptions/SUBSCRIPTION_ID'
response = (
service.subscriptions()
.patch(name=NAME, updateMask='ttl', body=BODY)
.execute()
)
print(response)
다음을 바꿉니다.
SCOPES
: 정기 결제의 각 이벤트 유형을 지원하는 하나 이상의 OAuth 범위입니다. 문자열 배열로 형식이 지정됩니다. 여러 범위를 나열하려면 쉼표로 구분하세요.
'https://www.googleapis.com/auth/chat.spaces.readonly',
'https://www.googleapis.com/auth/chat.memberships.readonly'
를 예로 들 수 있습니다.
SUBSCRIPTION_ID
: 정기 결제의 ID입니다. ID를 가져오려면 다음 중 하나를 사용하세요.
-
uid
필드의 값입니다.
-
name
필드에 표시된 리소스 이름의 ID입니다. 예를 들어 리소스 이름이 subscriptions/subscription-123
이면 subscription-123
을 사용합니다.
작업 디렉터리에 OAuth 클라이언트 ID 사용자 인증 정보를 저장하고 파일 이름을 credentials.json
로 지정했는지 확인합니다. 코드 샘플은 이 JSON 파일을 사용하여 Google Workspace에서 인증하고 사용자 인증 정보를 가져옵니다. 자세한 내용은 OAuth 클라이언트 ID 사용자 인증 정보 만들기를 참고하세요.
Google Workspace 구독을 업데이트하려면 터미널에서 다음을 실행합니다.
python3 update_subscription.py
Google Workspace Events API는
Subscription
리소스의 인스턴스를 포함하는
장기 실행 작업을 반환합니다.
업데이트된 Subscription
리소스에 관한 세부정보를 가져오려면 operations.get()
메서드를 사용하고 subscriptions.update()
요청에서 반환된 Operation
리소스를 지정합니다. 그렇지 않고 이전 버전의 정기 결제에서 Operation
리소스를 지정하면 응답이 비어 있습니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-21(UTC)
[null,null,["최종 업데이트: 2025-08-21(UTC)"],[[["\u003cp\u003eThis page provides instructions on renewing a Google Workspace subscription to its maximum expiration time using the \u003ccode\u003esubscriptions.update()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eYou can also use the \u003ccode\u003esubscriptions.update()\u003c/code\u003e method to update the list of event types to receive or to update the expiration time of a subscription.\u003c/p\u003e\n"],["\u003cp\u003eCode samples are provided in Apps Script and Python demonstrating how to renew a subscription.\u003c/p\u003e\n"],["\u003cp\u003eBefore renewing, you'll need an existing Google Workspace subscription, appropriate user authentication, and necessary tools like an Apps Script project or Python environment.\u003c/p\u003e\n"]]],["The core function described is renewing a Google Workspace subscription using the `subscriptions.update()` method. This involves updating the `ttl` field of the subscription resource to `0` to set the maximum expiration time. The process requires authentication with specific scopes and OAuth client ID credentials. Code examples are provided for Apps Script and Python, detailing how to execute the update, and how to retrieve the updated subscription resource via `operations.get()`. It also mentions that the update can include changes to event types.\n"],null,["# Update or renew a Google Workspace subscription\n\nThis page explains how to renew a Google Workspace subscription using the\n[`subscriptions.update()`](/workspace/events/reference/rest/v1/subscriptions/patch)\nmethod. You can use this method to update the expiration time of a subscription,\nincluding renewing the subscription for the maximum expiration time possible, or\nto update the list of event types to receive about the target resource. \n\n### Apps Script\n\n- \u003cbr /\u003e\n\n A Google Workspace subscription. To create one, see [Create a subscription](/workspace/events/guides/create-subscription).\n\n \u003cbr /\u003e\n\n- Requires user authentication with one or more\n [scopes that support all event types for\n the subscription](/workspace/events/guides/auth#scopes-event-type).\n\n | **Note:** To run the code sample in this guide, you must use the same [OAuth client\n | ID credentials](/workspace/events/guides/create-subscription#create-oauth) that you used to create the subscription.\n\n\u003c!-- --\u003e\n\n- An Apps Script project:\n - Use your Google Cloud project instead of the default one created automatically by Apps Script.\n - For all scopes that you added to configure the OAuth consent screen, you must also add the scopes to the `appsscript.json` file in your Apps Script project. For example, if you specified the `chat.messages` scope, then add the following: \n\n ```console\n \"oauthScopes\": [\n \"https://www.googleapis.com/auth/chat.messages\"\n ]\n \n ```\n - [Enable](/apps-script/guides/services/advanced#enable_advanced_services) the `Google Workspace Events` advanced service.\n\n### Python\n\n- Python 3.6 or greater\n- The [pip](https://pypi.org/project/pip/) package management tool\n- The latest Google client libraries for Python. To install or update them, run the following command in your command-line interface: \n\n ```console\n pip3 install --upgrade google-api-python-client google-auth-oauthlib\n \n ```\n\n\u003c!-- --\u003e\n\n- \u003cbr /\u003e\n\n A Google Workspace subscription. To create one, see [Create a subscription](/workspace/events/guides/create-subscription).\n\n \u003cbr /\u003e\n\n- Requires user authentication with one or more\n [scopes that support all event types for\n the subscription](/workspace/events/guides/auth#scopes-event-type).\n\n | **Note:** To run the code sample in this guide, you must use the same [OAuth client\n | ID credentials](/workspace/events/guides/create-subscription#create-oauth) that you used to create the subscription.\n\nRenew a Google Workspace subscription\n-------------------------------------\n\nIn this section, you use the Google Workspace Events API's\n`subscriptions.update()` method to renew a subscription to its maximum\nexpiration time. To specify the maximum expiration time, you update the `ttl`\nfield of the\n[`Subscription`](/workspace/events/reference/rest/v1/subscriptions) resource\nto `0`.\n\nThe maximum expiration time depends on what resource data is included in the\nevent payload. To learn more about expiration times, see [Event data for\nGoogle Workspace events](/workspace/events/guides#data).\n\nTo renew a Google Workspace subscription: \n\n### Apps Script\n\n1. In your Apps Script project, create a new script file\n named `updateSubscription` and add the following code:\n\n function updateSubscription() {\n // The name of the subscription to update.\n const name = 'subscriptions/\u003cvar translate=\"no\"\u003eSUBSCRIPTION_ID\u003c/var\u003e';\n\n // Call the Workspace Events API using the advanced service.\n const response = WorkspaceEvents.Subscriptions.patch({\n ttl: '0s',\n }, name);\n console.log(response);\n }\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eSUBSCRIPTION_ID\u003c/var\u003e: The ID of the subscription. To get the ID, you can use any of the following:\n - The value of the [`uid`](/workspace/events/reference/rest/v1/subscriptions#Subscription.FIELDS.uid) field.\n - The ID of the resource name represented in the [`name`](/workspace/events/reference/rest/v1/subscriptions#Subscription.FIELDS.name) field. For example, if the resource name is `subscriptions/subscription-123`, use `subscription-123`.\n2. To update the Google Workspace subscription, run the function\n `updateSubscription` in your Apps Script project.\n\n### Python\n\n1. In your working directory, create a file named `update_subscription.py`\n and add the following code:\n\n \"\"\"Update subscription.\"\"\"\n\n from google_auth_oauthlib.flow import InstalledAppFlow\n from googleapiclient.discovery import build\n\n # Specify required scopes.\n SCOPES = [\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eSCOPES\u003c/span\u003e\u003c/var\u003e]\n\n # Authenticate with Google Workspace and get user authentication.\n flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)\n CREDENTIALS = flow.run_local_server()\n\n # Call the Workspace Events API using the service endpoint.\n service = build(\n 'workspaceevents',\n 'v1',\n credentials=CREDENTIALS,\n )\n\n BODY = {\n 'ttl': {'seconds': 0},\n }\n NAME = 'subscriptions/\u003cvar translate=\"no\"\u003eSUBSCRIPTION_ID\u003c/var\u003e'\n response = (\n service.subscriptions()\n .patch(name=NAME, updateMask='ttl', body=BODY)\n .execute()\n )\n print(response)\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eSCOPES\u003c/var\u003e: One or more [OAuth scopes](/workspace/events/guides/auth) that support each event type for the subscription. Formatted as an array of strings. To list multiple scopes, separate by commas. For example, `'https://www.googleapis.com/auth/chat.spaces.readonly',\n 'https://www.googleapis.com/auth/chat.memberships.readonly'`.\n - \u003cvar translate=\"no\"\u003eSUBSCRIPTION_ID\u003c/var\u003e: The ID of the subscription. To get the ID, you can use any of the following:\n - The value of the [`uid`](/workspace/events/reference/rest/v1/subscriptions#Subscription.FIELDS.uid) field.\n - The ID of the resource name represented in the [`name`](/workspace/events/reference/rest/v1/subscriptions#Subscription.FIELDS.name) field. For example, if the resource name is `subscriptions/subscription-123`, use `subscription-123`.\n2. In your working directory, make sure you've stored your OAuth client ID\n credentials and named the file `credentials.json`. The code sample uses this JSON\n file to authenticate with Google Workspace and get user credentials. For instructions,\n see [Create OAuth client ID\n credentials](/workspace/events/guides/create-subscription#create-oauth).\n\n3. To update the Google Workspace subscription, run the following in\n your terminal:\n\n python3 update_subscription.py\n\nThe Google Workspace Events API returns a [long-running operation](/workspace/events/reference/rest/v1/operations) that contains the instance of the `Subscription` resource.\n\nTo get details about the updated `Subscription` resource, use the\n[`operations.get()`](/workspace/events/reference/rest/v1/operations/get) method\nand specify the `Operation` resource returned from your `subscriptions.update()`\nrequest. Otherwise, if you specify a `Operation` resource from a previous\nversion of the subscription, the response is empty.\n\nRelated topics\n--------------\n\n- [Get a subscription](/workspace/events/guides/get-subscription)\n- [List subscriptions](/workspace/events/guides/list-subscriptions)\n- [Create a subscription](/workspace/events/guides/create-subscription)\n- [Resolve errors and reactivate a subscription](/workspace/events/guides/reactivate-subscription)\n- [Delete a subscription](/workspace/events/guides/delete-subscription)"]]