使用会议聊天室

Google Meet REST API 插图

本指南介绍了如何在 Google Meet REST API 的 spaces 资源上创建、获取和更新会议室,以及结束正在进行的会议。

会议空间表示召开会议的虚拟场所或持久性对象(例如会议室)。一个聊天室中任何时候只能有一场正在进行的会议。会议室还可帮助用户会面和查找共享资源。

如需了解如何以编程方式配置会议室,请参阅配置会议室和成员

下表详细介绍了使用会议室方法所需的会议角色:

方法 所有者 参与者 其他
endActiveConference() x
get() x x x
     with settings x
     有正在进行的会议 x x
patch() x

通过用户凭据进行身份验证和授权后,Google Meet 应用便可访问用户数据,并代表已通过身份验证的用户执行操作。通过全网域授权进行身份验证后,您可以授权应用的服务账号访问用户的数据,而无需经过每位用户的同意。

Meet 如何识别会议室

Google Meet REST API 会为每个会议室生成一个 spaces 资源。name 字段是资源的资源名称。

以下是使用 name 字段标识会议室的两种重要方法:

  • space 是聊天室的资源标识符,格式为 spaces/{space}。这是服务器生成的唯一 ID,区分大小写。例如 spaces/jQCFfuBOdN5z

  • meetingCode 是聊天室的别名,格式为 spaces/{meetingCode}。它是一个可输入的唯一字符串,不区分大小写。例如 abc-mnop-xyz。长度不得超过 128 个字符。它是 meetingUri 的一部分:https://meet.google.com/abc-mnop-xyz

如需管理会议室,请为 {name} 字段使用以下值:

  • 如需获取会议室的详细信息,您可以使用 spaces/{space} 或别名 spaces/{meetingCode}。如需了解详情,请参阅获取会议空间

  • 如需更新会议室的详细信息,您只能使用 spaces/{space}。如需了解详情,请参阅更新会议空间

  • 如需在会议室内结束正在进行的会议,您只能使用 spaces/{space}。如需了解详情,请参阅结束正在进行的会议

创建会议空间

如需创建会议室,请对 spaces 资源使用 create() 方法。

该方法会返回 spaces 资源的实例,其中包含会议室配置的 SpaceConfig 对象。它还包含 ActiveConference 对象,该对象是指向会议室内当前 conferenceRecords 资源的链接。

以下代码示例展示了如何创建会议室:

Java

java-meet/samples/snippets/generated/com/google/apps/meet/v2/spacesservice/createspace/AsyncCreateSpace.java
import com.google.api.core.ApiFuture;
import com.google.apps.meet.v2.CreateSpaceRequest;
import com.google.apps.meet.v2.Space;
import com.google.apps.meet.v2.SpacesServiceClient;

public class AsyncCreateSpace {

  public static void main(String[] args) throws Exception {
    asyncCreateSpace();
  }

  public static void asyncCreateSpace() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (SpacesServiceClient spacesServiceClient = SpacesServiceClient.create()) {
      CreateSpaceRequest request =
          CreateSpaceRequest.newBuilder().setSpace(Space.newBuilder().build()).build();
      ApiFuture<Space> future = spacesServiceClient.createSpaceCallable().futureCall(request);
      // Do something.
      Space response = future.get();
    }
  }
}

Node.js

packages/google-apps-meet/samples/generated/v2/spaces_service.create_space.js
/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Space to be created. As of May 2023, the input space can be empty. Later on
 *  the input space can be non-empty when space configuration is introduced.
 */
// const space = {}

// Imports the Meet library
const {SpacesServiceClient} = require('@google-apps/meet').v2;

// Instantiates a client
const meetClient = new SpacesServiceClient();

async function callCreateSpace() {
  // Construct request
  const request = {
  };

  // Run request
  const response = await meetClient.createSpace(request);
  console.log(response);
}

callCreateSpace();

Python

packages/google-apps-meet/samples/generated_samples/meet_v2_generated_spaces_service_create_space_async.py
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.apps import meet_v2


async def sample_create_space():
    # Create a client
    client = meet_v2.SpacesServiceAsyncClient()

    # Initialize request argument(s)
    request = meet_v2.CreateSpaceRequest(
    )

    # Make the request
    response = await client.create_space(request=request)

    # Handle the response
    print(response)

获取会议室的详细信息

如需获取有关有效会议室及其设置的详细信息,请对 spaces 资源使用 get() 方法,并指定 name。如需了解详情,请参阅 Meet 如何识别会议空间

该方法会将会议室作为 spaces 资源的实例返回。

以下代码示例展示了如何检索会议室:

Java

java-meet/samples/snippets/generated/com/google/apps/meet/v2/spacesservice/getspace/AsyncGetSpace.java
import com.google.api.core.ApiFuture;
import com.google.apps.meet.v2.GetSpaceRequest;
import com.google.apps.meet.v2.Space;
import com.google.apps.meet.v2.SpaceName;
import com.google.apps.meet.v2.SpacesServiceClient;

public class AsyncGetSpace {

  public static void main(String[] args) throws Exception {
    asyncGetSpace();
  }

  public static void asyncGetSpace() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (SpacesServiceClient spacesServiceClient = SpacesServiceClient.create()) {
      GetSpaceRequest request =
          GetSpaceRequest.newBuilder().setName(SpaceName.of("[SPACE]").toString()).build();
      ApiFuture<Space> future = spacesServiceClient.getSpaceCallable().futureCall(request);
      // Do something.
      Space response = future.get();
    }
  }
}

Node.js

packages/google-apps-meet/samples/generated/v2/spaces_service.get_space.js
/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. Resource name of the space.
 *  Format: `spaces/{space}` or `spaces/{meetingCode}`.
 *  `{space}` is the resource identifier for the space. It's a unique,
 *  server-generated ID and is case sensitive. For example, `jQCFfuBOdN5z`.
 *  `{meetingCode}` is an alias for the space. It's a typeable, unique
 *  character string and is non-case sensitive. For example, `abc-mnop-xyz`.
 *  The maximum length is 128 characters.
 *  A `meetingCode` shouldn't be stored long term as it can become
 *  dissociated from a meeting space and can be reused for different meeting
 *  spaces in the future. Generally, a `meetingCode` expires 365 days after
 *  last use. For more information, see Learn about meeting codes in Google
 *  Meet (https://support.google.com/meet/answer/10710509).
 *  For more information, see How Meet identifies a meeting
 *  space (https://developers.google.com/meet/api/guides/meeting-spaces#identify-meeting-space).
 */
// const name = 'abc123'

// Imports the Meet library
const {SpacesServiceClient} = require('@google-apps/meet').v2;

// Instantiates a client
const meetClient = new SpacesServiceClient();

async function callGetSpace() {
  // Construct request
  const request = {
    name,
  };

  // Run request
  const response = await meetClient.getSpace(request);
  console.log(response);
}

callGetSpace();

Python

packages/google-apps-meet/samples/generated_samples/meet_v2_generated_spaces_service_get_space_async.py
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.apps import meet_v2


async def sample_get_space():
    # Create a client
    client = meet_v2.SpacesServiceAsyncClient()

    # Initialize request argument(s)
    request = meet_v2.GetSpaceRequest(
        name="name_value",
    )

    # Make the request
    response = await client.get_space(request=request)

    # Handle the response
    print(response)

将聊天室名称值替换为会议聊天室的唯一服务器生成 ID。

更新会议空间

如需更新会议室的详细信息,请对 spaces 资源使用 patch() 方法,并指定 name。如需了解详情,请参阅 Meet 如何识别会议空间

patch() 方法还接受可选的 updateMask 查询参数。该字段的类型为 FieldMask。这是您要更新的聊天室中字段的逗号分隔列表。

该方法会将会议室作为 spaces 资源的实例返回。

以下代码示例展示了如何更新会议室:

Java

java-meet/samples/snippets/generated/com/google/apps/meet/v2/spacesservice/updatespace/AsyncUpdateSpace.java
import com.google.api.core.ApiFuture;
import com.google.apps.meet.v2.Space;
import com.google.apps.meet.v2.SpacesServiceClient;
import com.google.apps.meet.v2.UpdateSpaceRequest;
import com.google.protobuf.FieldMask;

public class AsyncUpdateSpace {

  public static void main(String[] args) throws Exception {
    asyncUpdateSpace();
  }

  public static void asyncUpdateSpace() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (SpacesServiceClient spacesServiceClient = SpacesServiceClient.create()) {
      UpdateSpaceRequest request =
          UpdateSpaceRequest.newBuilder()
              .setSpace(Space.newBuilder().build())
              .setUpdateMask(FieldMask.newBuilder().build())
              .build();
      ApiFuture<Space> future = spacesServiceClient.updateSpaceCallable().futureCall(request);
      // Do something.
      Space response = future.get();
    }
  }
}

Node.js

packages/google-apps-meet/samples/generated/v2/spaces_service.update_space.js
/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. Space to be updated.
 */
// const space = {}
/**
 *  Optional. Field mask used to specify the fields to be updated in the space.
 *  If update_mask isn't provided(not set, set with empty paths, or only has ""
 *  as paths), it defaults to update all fields provided with values in the
 *  request.
 *  Using "*" as update_mask will update all fields, including deleting fields
 *  not set in the request.
 */
// const updateMask = {}

// Imports the Meet library
const {SpacesServiceClient} = require('@google-apps/meet').v2;

// Instantiates a client
const meetClient = new SpacesServiceClient();

async function callUpdateSpace() {
  // Construct request
  const request = {
    space,
  };

  // Run request
  const response = await meetClient.updateSpace(request);
  console.log(response);
}

callUpdateSpace();

Python

packages/google-apps-meet/samples/generated_samples/meet_v2_generated_spaces_service_update_space_async.py
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.apps import meet_v2


async def sample_update_space():
    # Create a client
    client = meet_v2.SpacesServiceAsyncClient()

    # Initialize request argument(s)
    request = meet_v2.UpdateSpaceRequest(
    )

    # Make the request
    response = await client.update_space(request=request)

    # Handle the response
    print(response)

将聊天室名称值替换为会议聊天室的唯一服务器生成 ID。

结束正在进行的会议

如需结束会议室中正在进行的会议(如果有),请对 spaces 资源使用 endActiveConference() 方法。请求正文和响应正文均为空。如需了解详情,请参阅Meet 如何识别会议空间

以下代码示例展示了如何结束正在进行的会议:

Java

java-meet/samples/snippets/generated/com/google/apps/meet/v2/spacesservice/endactiveconference/AsyncEndActiveConference.java
import com.google.api.core.ApiFuture;
import com.google.apps.meet.v2.EndActiveConferenceRequest;
import com.google.apps.meet.v2.SpaceName;
import com.google.apps.meet.v2.SpacesServiceClient;
import com.google.protobuf.Empty;

public class AsyncEndActiveConference {

  public static void main(String[] args) throws Exception {
    asyncEndActiveConference();
  }

  public static void asyncEndActiveConference() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (SpacesServiceClient spacesServiceClient = SpacesServiceClient.create()) {
      EndActiveConferenceRequest request =
          EndActiveConferenceRequest.newBuilder()
              .setName(SpaceName.of("[SPACE]").toString())
              .build();
      ApiFuture<Empty> future =
          spacesServiceClient.endActiveConferenceCallable().futureCall(request);
      // Do something.
      future.get();
    }
  }
}

Node.js

packages/google-apps-meet/samples/generated/v2/spaces_service.end_active_conference.js
/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. Resource name of the space.
 *  Format: `spaces/{space}`.
 *  `{space}` is the resource identifier for the space. It's a unique,
 *  server-generated ID and is case sensitive. For example, `jQCFfuBOdN5z`.
 *  For more information, see How Meet identifies a meeting
 *  space (https://developers.google.com/meet/api/guides/meeting-spaces#identify-meeting-space).
 */
// const name = 'abc123'

// Imports the Meet library
const {SpacesServiceClient} = require('@google-apps/meet').v2;

// Instantiates a client
const meetClient = new SpacesServiceClient();

async function callEndActiveConference() {
  // Construct request
  const request = {
    name,
  };

  // Run request
  const response = await meetClient.endActiveConference(request);
  console.log(response);
}

callEndActiveConference();

Python

packages/google-apps-meet/samples/generated_samples/meet_v2_generated_spaces_service_end_active_conference_async.py
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.apps import meet_v2


async def sample_end_active_conference():
    # Create a client
    client = meet_v2.SpacesServiceAsyncClient()

    # Initialize request argument(s)
    request = meet_v2.EndActiveConferenceRequest(
        name="name_value",
    )

    # Make the request
    await client.end_active_conference(request=request)

将聊天室名称值替换为会议聊天室的唯一服务器生成 ID。