ดูรายละเอียดเกี่ยวกับการสมัครใช้บริการ Google Workspace
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
หน้านี้อธิบายวิธีดูรายละเอียดเกี่ยวกับการสมัครใช้บริการ Google Workspace
โดยใช้เมธอด
subscriptions.get()
เมื่อเรียกใช้เมธอดนี้ด้วยการตรวจสอบสิทธิ์ผู้ใช้ เมธอดจะแสดงรายละเอียดเกี่ยวกับการสมัครใช้บริการที่ผู้ใช้ให้สิทธิ์ เมื่อใช้การตรวจสอบสิทธิ์ของแอป
วิธีการนี้จะแสดงรายละเอียดเกี่ยวกับการสมัครใช้บริการของแอป
ได้
ข้อกำหนดเบื้องต้น
Python
- Python 3.6 ขึ้นไป
- เครื่องมือจัดการแพ็กเกจ pip
- ไลบรารีของไคลเอ็นต์ Google ล่าสุดสำหรับ Python หากต้องการติดตั้งหรืออัปเดต ให้เรียกใช้คำสั่งต่อไปนี้
ในอินเทอร์เฟซบรรทัดคำสั่ง
pip3 install --upgrade google-api-python-client google-auth-oauthlib
- การสมัครใช้บริการ Google Workspace หากต้องการสร้าง ให้ดูสร้างการสมัครใช้บริการ
ต้องมีการตรวจสอบสิทธิ์
- สำหรับการตรวจสอบสิทธิ์ผู้ใช้ ต้องมี
ขอบเขตที่รองรับประเภทเหตุการณ์อย่างน้อย 1 ประเภทสำหรับการสมัครใช้บริการ ดูวิธีระบุขอบเขตได้ที่ขอบเขตตามประเภทเหตุการณ์
- สำหรับการตรวจสอบสิทธิ์แอป ต้องใช้ขอบเขต
chat.bot
(แอป Google Chat เท่านั้น)
รับการสมัครใช้บริการที่ผู้ใช้ให้สิทธิ์
ตัวอย่างโค้ดต่อไปนี้จะรับรายละเอียดเกี่ยวกับทรัพยากร
Subscription
โดยใช้การตรวจสอบสิทธิ์ของผู้ใช้ เมื่อตรวจสอบสิทธิ์ในฐานะผู้ใช้ เมธอดจะแสดงผล
การสมัครใช้บริการที่ผู้ใช้ให้สิทธิ์แอปในการสร้าง
วิธีรับการสมัครใช้บริการที่ผู้ใช้ให้สิทธิ์
Apps Script
ในโปรเจ็กต์ Apps Script ให้สร้างไฟล์สคริปต์ใหม่
ชื่อ getSubscription
แล้วเพิ่มโค้ดต่อไปนี้
function getSubscription() {
// The name of the subscription to get.
const name = 'subscriptions/SUBSCRIPTION_ID';
// Call the Workspace Events API using the advanced service.
const subscription = WorkspaceEvents.Subscriptions.get(name);
console.log(subscription);
}
แทนที่ค่าต่อไปนี้
SUBSCRIPTION_ID
: รหัสของการสมัครใช้บริการ หากต้องการรับรหัส คุณสามารถใช้ตัวเลือกต่อไปนี้
- ค่าของฟิลด์
uid
- รหัสของชื่อทรัพยากรที่แสดงในฟิลด์
name
เช่น หากชื่อทรัพยากรคือ
subscriptions/subscription-123
ให้ใช้ subscription-123
หากต้องการรับการสมัครใช้บริการ ให้เรียกใช้ฟังก์ชัน getSubscription
ในโปรเจ็กต์ Apps Script
Python
สร้างไฟล์ชื่อ get_subscription.py
ในไดเรกทอรีการทำงาน
แล้วเพิ่มโค้ดต่อไปนี้
"""Get subscription."""
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
# Specify required scopes.
SCOPES = ['SCOPE']
# 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,
)
NAME = 'subscriptions/SUBSCRIPTION_ID'
subscription = service.subscriptions().get(name=NAME).execute()
print(subscription)
แทนที่ค่าต่อไปนี้
SCOPE
: ขอบเขต OAuth ที่รองรับเหตุการณ์อย่างน้อย
1 ประเภทจากการสมัครใช้บริการ เช่น หากการสมัครใช้บริการของคุณได้รับกิจกรรม
พื้นที่ใน Chat ที่อัปเดตแล้ว https://www.googleapis.com/auth/chat.spaces.readonly
SUBSCRIPTION_ID
: รหัสของการสมัครใช้บริการ หากต้องการรับรหัส คุณสามารถใช้ตัวเลือกต่อไปนี้
- ค่าของฟิลด์
uid
- รหัสของชื่อทรัพยากรที่แสดงในฟิลด์
name
เช่น หากชื่อทรัพยากรคือ
subscriptions/subscription-123
ให้ใช้ subscription-123
ตรวจสอบว่าคุณได้จัดเก็บข้อมูลเข้าสู่ระบบรหัสไคลเอ็นต์ OAuth
และตั้งชื่อไฟล์เป็น credentials.json
ในไดเรกทอรีการทำงาน ตัวอย่างโค้ดใช้ไฟล์ JSON
นี้เพื่อตรวจสอบสิทธิ์กับ Google Workspace และรับข้อมูลเข้าสู่ระบบของผู้ใช้ โปรดดูวิธีการที่หัวข้อสร้างข้อมูลเข้าสู่ระบบ
รหัสไคลเอ็นต์ OAuth
หากต้องการสมัครใช้บริการ ให้เรียกใช้คำสั่งต่อไปนี้ในเทอร์มินัล
python3 get_subscription.py
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-21 UTC
[null,null,["อัปเดตล่าสุด 2025-08-21 UTC"],[[["\u003cp\u003eThis page provides instructions for retrieving details about a Google Workspace subscription using the \u003ccode\u003esubscriptions.get()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eYou can get details about user-authorized subscriptions using user authentication or any subscription for the app using app authentication.\u003c/p\u003e\n"],["\u003cp\u003eCode samples are provided in Apps Script and Python demonstrating how to retrieve subscription details.\u003c/p\u003e\n"],["\u003cp\u003ePrerequisites include a Google Workspace subscription, proper authentication, and specific environment setups for Apps Script and Python.\u003c/p\u003e\n"],["\u003cp\u003eRelated topics cover subscription management tasks like updating, resolving errors, deleting, listing, and creating subscriptions.\u003c/p\u003e\n"]]],[],null,["# Get details about a Google Workspace subscription\n\nThis page explains how to get details about a Google Workspace subscription\nusing the\n[`subscriptions.get()`](/workspace/events/reference/rest/v1/subscriptions/get)\nmethod.\n\nWhen you call this method with user authentication, the method returns\ndetails about a subscription authorized by the user. When you use app\nauthentication, the method can return details about any subscription for the\napp.\n\nPrerequisites\n-------------\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 [authentication](/workspace/events/guides/auth):\n\n - For user authentication, requires a scope that supports at least one of the event types for the subscription. To identify a scope, see [Scopes by event type](/workspace/events/guides/auth#scopes-event-type). **Note:** To run the code sample in this guide, you must use the same [OAuth\n | client ID credentials](/workspace/events/guides/create-subscription#create-oauth) that you used to create the subscription.\n - For app authentication, requires the `chat.bot` scope (Google Chat apps only).\n\nGet a subscription authorized by a user\n---------------------------------------\n\nThe following code sample gets details about a\n[`Subscription`](/workspace/events/reference/rest/v1/subscriptions)resource\nusing user authentication. When authenticated as a user, the method returns a\nsubscription that the user authorized the app to create.\n\nTo get a subscription authorized by a user: \n\n### Apps Script\n\n1. In your Apps Script project, create a new script file\n named `getSubscription` and add the following code:\n\n function getSubscription() {\n // The name of the subscription to get.\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 subscription = WorkspaceEvents.Subscriptions.get(name);\n console.log(subscription);\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 get the subscription, run the function `getSubscription` in\n your Apps Script project.\n\n### Python\n\n1. In your working directory, create a file named `get_subscription.py`\n and add the following code:\n\n \"\"\"Get 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\"\u003eSCOPE\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 NAME = 'subscriptions/\u003cvar translate=\"no\"\u003eSUBSCRIPTION_ID\u003c/var\u003e'\n subscription = service.subscriptions().get(name=NAME).execute()\n print(subscription)\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eSCOPE\u003c/var\u003e: An OAuth scope that [supports at least\n one event type from the subscription](/workspace/events/guides/auth#scopes-event-type). For example, if your subscription receives events an updated Chat space, `https://www.googleapis.com/auth/chat.spaces.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 get the subscription, run the following in your terminal:\n\n python3 get_subscription.py\n\nRelated topics\n--------------\n\n- [Update or renew a subscription](/workspace/events/guides/update-subscription)\n- [Resolve errors and reactivate a subscription](/workspace/events/guides/reactivate-subscription)\n- [Delete a subscription](/workspace/events/guides/delete-subscription)\n- [List subscriptions](/workspace/events/guides/list-subscriptions)\n- [Create a subscription](/workspace/events/guides/create-subscription)"]]