使用 Python 和 Google Meet REST API 觀察會議事件

本教學課程說明如何搭配使用 Google Meet REST API、Google Workspace Events API 和 Google Cloud Pub/Sub,觀察及回應 Meet 會議空間中的事件。這個範例應用程式會記錄會議開始和結束的時間、參與者加入或離開的時間,以及何時可取得產生的會議構件。

您可以訂閱 Meet 使用者,接收該使用者擁有或發起的任何會議空間活動,不必訂閱特定會議空間。詳情請參閱 Google Workspace Events API 說明文件中的「訂閱 Google Meet 事件」。

必要條件

如需為貴機構啟用上述任一必要條件,請要求 Google Workspace 管理員啟用:

準備環境

本節說明如何為本教學課程建立及設定本機環境和 Google Cloud 專案。

建立工作目錄和 Python 虛擬環境

如要建立及啟動新的虛擬環境,請在終端機中執行下列指令。

Linux/macOS

mkdir meet-tutorial
cd meet-tutorial
python3 -mvenv env
source env/bin/activate

Windows (命令提示字元)

mkdir meet-tutorial
cd meet-tutorial
python3 -mvenv env
env/bin/activate.bat

Windows (PowerShell)

mkdir meet-tutorial
cd meet-tutorial
python3 -mvenv env
env/bin/activate.ps1

建立 Google Cloud 專案

Google Cloud 控制台

  1. 前往 Google Cloud 控制台,依序點選「選單」圖示 >「IAM 與管理」 >「建立專案」

    前往「建立專案」

  2. 在「專案名稱」欄位中,輸入專案的描述性名稱。

    選用:如要編輯「專案 ID」,請按一下「編輯」。專案建立後就無法變更專案 ID,因此請選用符合專案執行期間需求的 ID。

  3. 在「Location」(位置) 欄位中,按一下「Browse」(瀏覽),顯示專案的可能位置。然後按一下「選取」
  4. 按一下「建立」,Google Cloud 控制台會前往「資訊主頁」頁面,並在幾分鐘內建立專案。

gcloud CLI

在下列任一開發環境中,存取 Google Cloud CLI (gcloud):

  • Cloud Shell:如要使用已設定 gcloud CLI 的線上終端機,請啟用 Cloud Shell。
    啟用 Cloud Shell
  • 本機殼層:如要使用本機開發環境,請安裝初始化 gcloud CLI。
    如要建立 Cloud 專案,請使用 gcloud projects create 指令:
    gcloud projects create PROJECT_ID
    PROJECT_ID 替換為要建立的專案 ID。

啟用 Google Cloud 專案的計費功能

Google Cloud 控制台

  1. 前往 Google Cloud 控制台的「帳單」頁面。依序點選「選單」「帳單」「我的專案」

    前往「我的專案」的帳單頁面

  2. 在「選取機構」中,選擇與 Google Cloud 專案相關聯的機構。
  3. 在專案列中開啟「動作」選單 (),然後按一下「變更帳單」,並選擇 Cloud 帳單帳戶。
  4. 按一下 [設定帳戶]

gcloud CLI

  1. 如要列出可用的帳單帳戶,請執行下列指令:
    gcloud billing accounts list
  2. 將帳單帳戶連結至 Google Cloud 專案:
    gcloud billing projects link PROJECT_ID --billing-account=BILLING_ACCOUNT_ID

    更改下列內容:

    • PROJECT_ID 是要啟用計費功能的 Cloud 專案的專案 ID
    • BILLING_ACCOUNT_ID 是要連結至 Google Cloud 專案的帳單帳戶 ID

設定驗證與授權

應用程式必須經過驗證和授權,才能存取 Meet REST API 資源。呼叫 Meet REST API 時,必須先完成使用者授權。本節說明如何設定使用者憑證及要求授權。

設定 OAuth 同意畫面並選擇範圍

下列步驟會建議您使用預留位置資訊,為應用程式設定 OAuth 同意畫面。請先更新這項資訊,再對外發布應用程式。

  1. 在 Google Cloud 控制台中,依序前往「選單」 > Google Auth platform >「品牌」

    前往「品牌宣傳」

  2. 如果您已設定 Google Auth platform,可以在「品牌」、「目標對象」和「資料存取」中設定下列 OAuth 同意畫面。 如果看到「尚未設定」Google Auth platform 訊息,請按一下「開始使用」
    1. 在「應用程式資訊」下方的「應用程式名稱」中,輸入 Meet REST API Tutorial
    2. 在「使用者支援電子郵件」中,選擇支援電子郵件地址,方便使用者在同意聲明方面有任何疑問時與您聯絡。
    3. 點選 [下一步]
    4. 在「目標對象」下方,選取「內部」
    5. 點選 [下一步]
    6. 在「聯絡資訊」下方,輸入可接收專案異動通知的電子郵件地址
    7. 點選 [下一步]
    8. 在「完成」部分,請詳閱《Google API 服務:使用者資料政策》,然後選取「我同意《Google API 服務:使用者資料政策》」
    9. 按一下 [繼續]。
    10. 按一下「Create」(建立)。
    11. 如果為使用者類型選取「外部」,請新增測試使用者:
      1. 按一下「目標對象」
      2. 在「測試使用者」下方,按一下「新增使用者」
      3. 輸入您的電子郵件地址和任何其他授權測試使用者,然後按一下「儲存」
  3. 依序點選「資料存取」>「新增或移除範圍」。系統會顯示面板,列出您在 Google Cloud 專案中啟用的各項 API 範圍。
  4. 在「手動新增範圍」下方,貼上下列範圍:
    • https://www.googleapis.com/auth/meetings.space.created
  5. 按一下「新增至表格」
  6. 按一下「更新」
  7. 選取應用程式所需的範圍後,按一下「儲存」

如要進一步瞭解如何設定 OAuth 同意畫面,請參閱「開始使用 Google Auth platform」一文。

建立用戶端 ID

在 OAuth 2.0 流程中,用戶端 ID 會做為應用程式的憑證。由於應用程式是在本機執行,請建立電腦版用戶端 ID。

  1. 前往 Google Cloud 控制台,依序點選「選單」圖示 > Google Auth platform >「用戶端」

    前往「客戶」

  2. 按一下「建立用戶端」
  3. 依序點選「應用程式類型」>「電腦應用程式」
  4. 在「Name」(名稱) 欄位中,輸入憑證名稱。這個名稱只會顯示在 Google Cloud 控制台中。
  5. 按一下 [Create] (建立)

    新建立的憑證會顯示在「OAuth 2.0 用戶端 ID」下方。

安裝 Google 驗證程式庫

安裝 Google 驗證程式庫:

pip install google-auth google-auth-oauthlib

執行授權

Meet REST API 需要使用者憑證,也就是 OAuth 2.0 存取權杖。在本節中,您會實作 OAuth 2.0 流程,為使用者要求存取權杖和更新權杖。

  1. 在工作目錄中建立 main.py 檔案,並加入下列內容:

    import os
    import json
    
    from google.auth.transport import requests
    from google.oauth2.credentials import Credentials
    from google_auth_oauthlib.flow import InstalledAppFlow
    
    def authorize() -> Credentials:
        """Ensure valid credentials for calling the Meet REST API."""
        CLIENT_SECRET_FILE = "./client_secret.json"
        credentials = None
    
        if os.path.exists('token.json'):
            credentials = Credentials.from_authorized_user_file('token.json')
    
        if credentials is None:
            flow = InstalledAppFlow.from_client_secrets_file(
                CLIENT_SECRET_FILE,
                scopes=[
                    'https://www.googleapis.com/auth/meetings.space.created',
                ])
            flow.run_local_server(port=0)
            credentials = flow.credentials
    
        if credentials and credentials.expired:
            credentials.refresh(requests.Request())
    
        if credentials is not None:
            with open("token.json", "w") as f:
                f.write(credentials.to_json())
    
        return credentials
    
    USER_CREDENTIALS = authorize()
    
  2. 如要執行程式碼,必須提供先前建立的用戶端 ID 和密鑰。將下載的用戶端密鑰檔案複製到專案工作目錄,並重新命名為 client_secret.json

  3. 如要測試授權運作方式,請執行下列指令。 要求獲得核准後,應用程式會提示授權,並在專案工作目錄中建立 token.json 檔案。

    python3 main.py

新增 Meet REST API

授權碼已完成,現在可以啟用並呼叫 Meet REST API。

啟用 API

本節著重於 Meet REST API,但本教學課程也會使用 Google Cloud Pub/Sub 和 Google Workspace Events API。

Google Cloud 控制台

  1. 在 Google Cloud 控制台中,啟用 Google Meet REST API、Google Workspace Events API 和 Google Cloud Pub/Sub。

    啟用 API

  2. 確認您要在正確的 Cloud 專案中啟用 API,然後按一下「下一步」

  3. 確認要啟用的 API 正確無誤,然後按一下「啟用」

gcloud CLI

  1. 如有必要,請使用 gcloud config set project 指令,將目前的 Cloud 專案設為您建立的專案:

    gcloud config set project PROJECT_ID

    PROJECT_ID 替換為您建立的 Cloud 專案的專案 ID

  2. 使用 gcloud services enable 指令啟用 Google Meet REST API、Google Workspace Events API 和 Google Cloud Pub/Sub:

    gcloud services enable meet.googleapis.com workspaceevents.googleapis.com pubsub.googleapis.com

安裝 Meet REST API 用戶端程式庫

如要安裝 Meet REST API 用戶端程式庫,請按照下列步驟操作:

  1. 執行下列指令:

    pip install google-apps-meet
  2. 編輯 main.py 檔案,匯入用戶端:

    from google.apps import meet_v2 as meet
    

建立聊天室

現在 Meet REST API 已推出,請定義函式來建立可訂閱的會議空間。

編輯 main.py 並新增:

def create_space() -> meet.Space:
    """Create a meeting space."""
    client = meet.SpacesServiceClient(credentials=USER_CREDENTIALS)
    request = meet.CreateSpaceRequest()
    return client.create_space(request=request)

訂閱活動

如要接收會議空間的相關事件,請使用 Google Workspace Events API 建立訂閱項目。您也必須建立及訂閱 Google Cloud Pub/Sub 主題,做為通知端點,讓應用程式接收事件。

設定 Google Cloud Pub/Sub

如要建立及訂閱 Pub/Sub 主題,請按照下列步驟操作:

Google Cloud 控制台

  1. 在 Google Cloud 控制台中,依序前往「選單」 >「Pub/Sub」

    前往「Pub/Sub」頁面

    確認已選取應用程式的 Cloud 專案。

  2. 按一下「建立主題」,然後執行下列步驟:
    1. 輸入 workspace-events 做為主題名稱。
    2. 保留已選取的「新增預設訂閱項目」
    3. 按一下「建立」,完整主題名稱的格式為 projects/{project}/topics/{topic}。請記下這個名稱,以便在後續步驟中使用。
  3. 授予將 Pub/Sub 訊息發布至主題的存取權:
    1. 在側邊面板中,開啟「權限」分頁。
    2. 按一下「新增主體」
    3. 在「New principals」(新增主體) 部分輸入 meet-api-event-push@system.gserviceaccount.com
    4. 在「指派角色」中選取 Pub/Sub Publisher
    5. 按一下 [儲存]

    更新主題權限可能需要幾分鐘。

gcloud CLI

  1. 在 Cloud 專案中執行下列指令,建立主題:
    gcloud pubsub topics create workspace-events

    輸出內容會顯示完整的主題名稱,格式為 projects/{project}/topics/{topic}。請記下這個名稱,以便在後續步驟中使用。

  2. 授予將訊息發布到主題的權限:
     gcloud pubsub topics add-iam-policy-binding workspace-events --member='serviceAccount:meet-api-event-push@system.gserviceaccount.com' --role='roles/pubsub.publisher'

    更新主題權限可能需要幾分鐘。

  3. 為主題建立 Pub/Sub 訂閱項目:
    gcloud pubsub subscriptions create workspace-events-sub --topic=TOPIC_NAME

    更改下列內容:

    • TOPIC_NAME:您在上一步中建立的主題名稱。

記下主題名稱,並確認 {project} 的值是您應用程式的 Cloud 專案 ID。您稍後會使用主題名稱建立 Google Workspace 訂閱項目。

建立服務帳戶

Google Cloud 控制台

  1. 在 Google Cloud 控制台中,依序前往「選單」圖示 >「IAM 與管理」 >「服務帳戶」

    前往「Service Accounts」(服務帳戶) 頁面

  2. 按一下「建立服務帳戶」
  3. 填寫服務帳戶詳細資料,然後按一下「建立並繼續」
  4. 在「將專案存取權授予這個服務帳戶」部分,新增下列角色:
    • roles/pubsub.subscriber
  5. 按一下「繼續」
  6. 選用:輸入可管理這個服務帳戶並執行動作的使用者或群組。詳情請參閱「管理服務帳戶模擬功能」。
  7. 按一下「完成」,記下服務帳戶的電子郵件地址。

gcloud CLI

  1. 建立服務帳戶:
    gcloud iam service-accounts create meet-event-listener \
      --display-name="meet-event-listener"
  2. 將必要角色指派給服務帳戶:
    gcloud projects add-iam-policy-binding PROJECT_ID \
      --member="serviceAccount:meet-event-listener@PROJECT_ID.iam.gserviceaccount.com" \
      --role="roles/pubsub.subscriber"

    PROJECT_ID 替換為您的 Google Cloud 專案 ID。

使用服務帳戶

建立服務帳戶後,請授予自己模擬服務帳戶的權限。

Google Cloud 控制台

  1. 在新建服務帳戶的「動作」欄中,依序點選 >「管理權限」
  2. 依序按一下「新增金鑰」 >「授予存取權」
  3. 在「新增主體」下方輸入電子郵件地址。
  4. 選取「服務帳戶」>「服務帳戶憑證建立者」做為角色。
  5. 按一下 [儲存]
  6. 返回終端機並使用 gcloud 登入,將應用程式預設憑證設為服務帳戶。系統提示授權時,請使用先前步驟中使用的帳戶登入。
    gcloud auth application-default login --impersonate-service-account=SERVICE_ACCOUNT_EMAIL

gcloud CLI

  1. 如要新增權限,請使用服務帳戶和使用者的電子郵件地址執行 gcloud iam service-accounts add-iam-policy-binding
    gcloud iam service-accounts add-iam-policy-binding \
      SERVICE_ACCOUNT_EMAIL \
      --member="user:YOUR_EMAIL" \
      --role="roles/iam.serviceAccountTokenCreator"
  2. 登入以將應用程式預設憑證設為服務帳戶。系統提示授權時,請使用先前步驟中使用的帳戶登入。
    gcloud auth application-default login --impersonate-service-account=SERVICE_ACCOUNT_EMAIL

安裝 Pub/Sub 用戶端程式庫

  1. 使用 pip 安裝 Pub/Sub 的用戶端程式庫:

    pip install google-cloud-pubsub
  2. 然後編輯 main.py 來匯入用戶端:

    from google.cloud import pubsub_v1
    

建立 Google Workspace 訂閱方案

將下列程式碼新增至 main.py,定義訂閱 Meet 事件的方法。這段程式碼會訂閱會議空間的所有事件。訂閱後,系統會將事件發布至 Pub/Sub 主題。

def subscribe_to_space(space_name: str = None, topic_name: str = None):
    """Subscribe to events for a meeting space."""
    session = requests.AuthorizedSession(USER_CREDENTIALS)
    body = {
        'targetResource': f"//meet.googleapis.com/{space_name}",
        "eventTypes": [
            "google.workspace.meet.conference.v2.started",
            "google.workspace.meet.conference.v2.ended",
            "google.workspace.meet.participant.v2.joined",
            "google.workspace.meet.participant.v2.left",
            "google.workspace.meet.recording.v2.fileGenerated",
            "google.workspace.meet.transcript.v2.fileGenerated",
        ],
        "payloadOptions": {
            "includeResource": False,
        },
        "notificationEndpoint": {
            "pubsubTopic": topic_name
        },
        "ttl": "86400s",
    }
    response = session.post("https://workspaceevents.googleapis.com/v1/subscriptions", json=body)
    return response

接著,新增對應的程式碼,以擷取及處理事件。

監聽及處理事件

繼續編輯 main.py,並新增下列範例程式碼。這段程式碼會實作接收端,並使用 Google Cloud Pub/Sub API 擷取可用的事件。各種處理常式方法會列印對應事件的相關資訊。

def format_participant(participant: meet.Participant) -> str:
    """Formats a participant for display on the console."""
    if participant.anonymous_user:
        return f"{participant.anonymous_user.display_name} (Anonymous)"

    if participant.signedin_user:
        return f"{participant.signedin_user.display_name} (ID: {participant.signedin_user.user})"

    if participant.phone_user:
        return f"{participant.phone_user.display_name} (Phone)"

    return "Unknown participant"


def fetch_participant_from_session(session_name: str) -> meet.Participant:
    """Fetches the participant for a session."""
    client = meet.ConferenceRecordsServiceClient(credentials=USER_CREDENTIALS)
    # Use the parent path of the session to fetch the participant details
    parsed_session_path = client.parse_participant_session_path(session_name)
    participant_resource_name = client.participant_path(
        parsed_session_path["conference_record"],
        parsed_session_path["participant"])
    return client.get_participant(name=participant_resource_name)


def on_conference_started(message: pubsub_v1.subscriber.message.Message):
    """Display information about a conference when started."""
    payload = json.loads(message.data)
    resource_name = payload.get("conferenceRecord").get("name")
    client = meet.ConferenceRecordsServiceClient(credentials=USER_CREDENTIALS)
    conference = client.get_conference_record(name=resource_name)
    print(f"Conference (ID {conference.name}) started at {conference.start_time.rfc3339()}")


def on_conference_ended(message: pubsub_v1.subscriber.message.Message):
    """Display information about a conference when ended."""
    payload = json.loads(message.data)
    resource_name = payload.get("conferenceRecord").get("name")
    client = meet.ConferenceRecordsServiceClient(credentials=USER_CREDENTIALS)
    conference = client.get_conference_record(name=resource_name)
    print(f"Conference (ID {conference.name}) ended at {conference.end_time.rfc3339()}")


def on_participant_joined(message: pubsub_v1.subscriber.message.Message):
    """Display information about a participant when they join a meeting."""
    payload = json.loads(message.data)
    resource_name = payload.get("participantSession").get("name")
    client = meet.ConferenceRecordsServiceClient(credentials=USER_CREDENTIALS)
    session = client.get_participant_session(name=resource_name)
    participant = fetch_participant_from_session(resource_name)
    display_name = format_participant(participant)
    print(f"{display_name} joined at {session.start_time.rfc3339()}")


def on_participant_left(message: pubsub_v1.subscriber.message.Message):
    """Display information about a participant when they leave a meeting."""
    payload = json.loads(message.data)
    resource_name = payload.get("participantSession").get("name")
    client = meet.ConferenceRecordsServiceClient(credentials=USER_CREDENTIALS)
    session = client.get_participant_session(name=resource_name)
    participant = fetch_participant_from_session(resource_name)
    display_name = format_participant(participant)
    print(f"{display_name} left at {session.end_time.rfc3339()}")


def on_recording_ready(message: pubsub_v1.subscriber.message.Message):
    """Display information about a recorded meeting when artifact is ready."""
    payload = json.loads(message.data)
    resource_name = payload.get("recording").get("name")
    client = meet.ConferenceRecordsServiceClient(credentials=USER_CREDENTIALS)
    recording = client.get_recording(name=resource_name)
    print(f"Recording available at {recording.drive_destination.export_uri}")


def on_transcript_ready(message: pubsub_v1.subscriber.message.Message):
    """Display information about a meeting transcript when artifact is ready."""
    payload = json.loads(message.data)
    resource_name = payload.get("transcript").get("name")
    client = meet.ConferenceRecordsServiceClient(credentials=USER_CREDENTIALS)
    transcript = client.get_transcript(name=resource_name)
    print(f"Transcript available at {transcript.docs_destination.export_uri}")


def on_message(message: pubsub_v1.subscriber.message.Message) -> None:
    """Handles an incoming event from the Google Cloud Pub/Sub API."""
    event_type = message.attributes.get("ce-type")
    handler = {
        "google.workspace.meet.conference.v2.started": on_conference_started,
        "google.workspace.meet.conference.v2.ended": on_conference_ended,
        "google.workspace.meet.participant.v2.joined": on_participant_joined,
        "google.workspace.meet.participant.v2.left": on_participant_left,
        "google.workspace.meet.recording.v2.fileGenerated": on_recording_ready,
        "google.workspace.meet.transcript.v2.fileGenerated": on_transcript_ready,
    }.get(event_type)

    try:
        if handler is not None:
            handler(message)
        message.ack()
    except Exception as error:
        print("Unable to process event")
        print(error)


def listen_for_events(subscription_name: str = None):
    """Subscribe to events on the subscription."""
    subscriber = pubsub_v1.SubscriberClient()
    with subscriber:
        future = subscriber.subscribe(subscription_name, callback=on_message)
        print("Listening for events")
        try:
            future.result()
        except KeyboardInterrupt:
            future.cancel()
    print("Done")

完成程式碼

將下列程式碼新增至 main.py,呼叫方法來建立空間、訂閱事件及監聽。使用您先前建立的主題和訂閱項目名稱,更新 TOPIC_NAMESUBSCRIPTION_NAME 常數。

  1. main.py 中加入程式碼:

    space = create_space()
    print(f"Join the meeting at {space.meeting_uri}")
    
    TOPIC_NAME = "projects/PROJECT_ID/topics/TOPIC_ID"
    SUBSCRIPTION_NAME = "projects/PROJECT_ID/subscriptions/SUBSCRIPTION_ID"
    
    subscription = subscribe_to_space(topic_name=TOPIC_NAME, space_name=space.name)
    if (subscription.status_code) == 200:
        listen_for_events(subscription_name=SUBSCRIPTION_NAME)
    else:
        print(f"Subscription to Meet events failed, response data: {subscription.content}")
    

    更改下列內容:

    • PROJECT_ID:應用程式的專屬 Cloud 專案 ID,例如 my-sample-project-191923

    • TOPIC_ID:您在 Cloud 專案中建立的 Pub/Sub 主題名稱。

    • SUBSCRIPTION_ID:訂閱項目名稱,例如 workspace-events-sub

  2. 執行程式:

    python3 main.py

如果您先前未執行過該程式,系統會在第一次執行時提示您授權。授予應用程式呼叫 Meet REST API 的權限。程式成功執行後,您應該會看到類似以下的輸出內容:

Join the meeting at https://meet.google.com/abc-mnop-xyz

加入電話會議

如要為應用程式產生事件,請使用應用程式顯示的網址加入會議。加入後,您可以嘗試下列動作來觸發事件:

  • 離開並重新加入會議。
  • 邀請其他使用者或撥打電話加入會議。
  • 啟用錄音和轉錄稿功能。

每項活動都會產生事件,應用程式會接收這些事件,並記錄到 Google Cloud 控制台。

完成後,請使用 ctrl-c 中斷程式。

選用:可嘗試執行的其他步驟

應用程式會記錄事件的基本詳細資料。如要繼續探索 Meet REST API,請嘗試修改應用程式,執行下列額外動作。

  • 使用 People API 擷取已登入參與者的其他資訊。

    def subscribe_to_user(user_name: str = None, topic_name: str = None) -> requests_lib.Response:
        """Subscribe to events for a user."""
        session = requests.AuthorizedSession(USER_CREDENTIALS)
        body = {
            "targetResource": f"//cloudidentity.googleapis.com/users/{user_name}",
            "eventTypes": [
                "google.workspace.meet.conference.v2.started",
                "google.workspace.meet.conference.v2.ended",
                "google.workspace.meet.participant.v2.joined",
                "google.workspace.meet.participant.v2.left",
                "google.workspace.meet.recording.v2.fileGenerated",
                "google.workspace.meet.transcript.v2.fileGenerated",
            ],
            "payloadOptions": {
                "includeResource": False,
            },
            "notificationEndpoint": {"pubsubTopic": topic_name},
            "ttl": "86400s",
        }
        response = session.post(
            "https://workspaceevents.googleapis.com/v1/subscriptions", json=body
        )
        return response
    
    service = build("people", "v1", credentials=USER_CREDENTIALS)
    response = (
        service.people()
        .get(resourceName="people/me", personFields="names,emailAddresses")
        .execute()
    )
    resource_name = response.get("resourceName")
    if resource_name.startswith("people/"):
        resource_name = resource_name[len("people/") :]
    
    subscription = subscribe_to_user(topic_name=TOPIC_NAME, user_name=resource_name)
    

    請務必在上述憑證範例的授權方法中新增「https://www.googleapis.com/auth/userinfo.profile」。

  • 使用 Google Drive API 下載錄音和轉錄稿。

  • 請使用 Meet REST API 中的結構化轉錄稿方法,而非從 Google 雲端硬碟下載轉錄稿。

  • 取得聊天室,而不是建立聊天室

    def get_space(meeting_code: str) -> meet.Space:
        """Get a meeting space."""
        client = meet.SpacesServiceClient(credentials=USER_CREDENTIALS)
        return client.get_space(name="spaces/" + meeting_code)
    

    請務必在上述憑證範例的授權方法中新增「https://www.googleapis.com/auth/meetings.space.readonly」。

選用:清除

如要避免系統向您的 Google Cloud 控制台帳戶收取本教學課程所用資源的費用,建議您清除建立的所有資源和專案。

如要刪除訂閱項目,請按照下列步驟操作:

控制台

  1. 在 Google Cloud 控制台中,依序前往「選單」 >「Pub/Sub」>「Subscriptions」(訂閱項目)

    前往「訂閱項目」頁面

  2. 選取訂閱項目,然後按一下「更多動作」

  3. 按一下 [Delete] (刪除),系統會顯示「刪除訂閱項目」視窗。

  4. 點選「刪除」。

gcloud CLI

  1. 刪除訂閱項目:

    gcloud pubsub subscriptions delete SUBSCRIPTION_NAME

如要刪除主題,請按照下列步驟操作:

控制台

  1. 在 Google Cloud 控制台中,依序前往「選單」 >「Pub/Sub」>「主題」

    前往「主題」

  2. 選取主題,然後按一下「更多動作」

  3. 按一下 [Delete] (刪除),系統會顯示「刪除主題」視窗。

  4. 輸入 delete,然後按一下「刪除」

gcloud CLI

  1. 刪除主題:

    gcloud pubsub topics delete TOPIC_NAME

如要刪除專案,請進行以下操作:

控制台

  1. 在 Google Cloud 控制台中,前往「管理資源」頁面。依序點選「選單」「IAM 與管理」「管理資源」

    前往 Resource Manager

  2. 在專案清單中選取要刪除的專案,然後按一下「Delete」(刪除) 圖示
  3. 在對話方塊中輸入專案 ID,然後按一下「Shut down」(關閉) 即可刪除專案。

gcloud CLI

  1. 如要刪除專案,請使用 gcloud projects delete 指令:

    gcloud projects delete PROJECT_ID