获取池

获取直播池资源的详细信息。

深入探索

如需查看包含此代码示例的详细文档,请参阅以下内容:

代码示例

C#

如需了解如何安装和使用 Live Stream API 客户端库,请参阅 Live Stream API 客户端库。 如需了解详情,请参阅 Live Stream API C# API 参考文档

如需向 Live Stream API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


using Google.Cloud.Video.LiveStream.V1;

public class GetPoolSample
{
    public Pool GetPool(
         string projectId, string locationId, string poolId)
    {
        // Create the client.
        LivestreamServiceClient client = LivestreamServiceClient.Create();

        GetPoolRequest request = new GetPoolRequest
        {
            PoolName = PoolName.FromProjectLocationPool(projectId, locationId, poolId)
        };

        // Make the request.
        Pool response = client.GetPool(request);
        return response;
    }
}

Go

如需了解如何安装和使用 Live Stream API 客户端库,请参阅 Live Stream API 客户端库。 有关详情,请参阅 Live Stream API Go API 参考文档

如需向 Live Stream API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

import (
	"context"
	"fmt"
	"io"

	livestream "cloud.google.com/go/video/livestream/apiv1"
	"cloud.google.com/go/video/livestream/apiv1/livestreampb"
)

// getPool gets a pool.
func getPool(w io.Writer, projectID, location, poolID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// poolID := "default"
	ctx := context.Background()
	client, err := livestream.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer client.Close()

	req := &livestreampb.GetPoolRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/pools/%s", projectID, location, poolID),
	}

	response, err := client.GetPool(ctx, req)
	if err != nil {
		return fmt.Errorf("GetPool: %w", err)
	}

	fmt.Fprintf(w, "Pool: %v", response.Name)
	return nil
}

Java

如需了解如何安装和使用 Live Stream API 客户端库,请参阅 Live Stream API 客户端库。 如需了解详情,请参阅 Live Stream API Java API 参考文档

如需向 Live Stream API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import com.google.cloud.video.livestream.v1.Pool;
import com.google.cloud.video.livestream.v1.PoolName;
import java.io.IOException;

public class GetPool {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project-id";
    String location = "us-central1";
    String poolId = "default"; // only 1 pool supported per location

    getPool(projectId, location, poolId);
  }

  public static void getPool(String projectId, String location, String poolId)
      throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. In this example, try-with-resources is used
    // which automatically calls close() on the client to clean up resources.
    try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
      PoolName name = PoolName.of(projectId, location, poolId);
      Pool response = livestreamServiceClient.getPool(name);
      System.out.println("Pool: " + response.getName());
    }
  }
}

Node.js

如需了解如何安装和使用 Live Stream API 的客户端库,请参阅 Live Stream API 客户端库。 有关详情,请参阅 Live Stream API Node.js API 参考文档

如需向 Live Stream API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// projectId = 'my-project-id';
// location = 'us-central1';
// poolId = 'my-pool';

// Imports the Livestream library
const {LivestreamServiceClient} = require('@google-cloud/livestream').v1;

// Instantiates a client
const livestreamServiceClient = new LivestreamServiceClient();

async function getPool() {
  // Construct request
  const request = {
    name: livestreamServiceClient.poolPath(projectId, location, poolId),
  };
  const [pool] = await livestreamServiceClient.getPool(request);
  console.log(`Pool: ${pool.name}`);
}

getPool();

PHP

如需了解如何安装和使用 Live Stream API 的客户端库,请参阅 Live Stream API 客户端库。 如需了解详情,请参阅 Live Stream API PHP API 参考文档

如需向 Live Stream API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\GetPoolRequest;

/**
 * Gets a pool.
 *
 * @param string  $callingProjectId   The project ID to run the API call under
 * @param string  $location           The location of the pool
 * @param string  $poolId             The ID of the pool
 */
function get_pool(
    string $callingProjectId,
    string $location,
    string $poolId
): void {
    // Instantiate a client.
    $livestreamClient = new LivestreamServiceClient();
    $formattedName = $livestreamClient->poolName($callingProjectId, $location, $poolId);

    // Get the pool.
    $request = (new GetPoolRequest())
        ->setName($formattedName);
    $response = $livestreamClient->getPool($request);
    // Print results
    printf('Pool: %s' . PHP_EOL, $response->getName());
}

Python

如需了解如何安装和使用 Live Stream API 的客户端库,请参阅 Live Stream API 客户端库。 有关详情,请参阅 Live Stream API Python API 参考文档

如需向 Live Stream API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


import argparse

from google.cloud.video import live_stream_v1
from google.cloud.video.live_stream_v1.services.livestream_service import (
    LivestreamServiceClient,
)


def get_pool(project_id: str, location: str, pool_id: str) -> live_stream_v1.types.Pool:
    """Gets a pool.
    Args:
        project_id: The GCP project ID.
        location: The location of the pool.
        pool_id: The user-defined pool ID."""

    client = LivestreamServiceClient()

    name = f"projects/{project_id}/locations/{location}/pools/{pool_id}"
    response = client.get_pool(name=name)
    print(f"Pool: {response.name}")

    return response

Ruby

如需了解如何安装和使用 Live Stream API 的客户端库,请参阅 Live Stream API 客户端库。 有关详情,请参阅 Live Stream API Ruby API 参考文档

如需向 Live Stream API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

require "google/cloud/video/live_stream"

##
# Get the pool
#
# @param project_id [String] Your Google Cloud project (e.g. "my-project")
# @param location [String] The location (e.g. "us-central1")
# @param pool_id [String] Your pool name (e.g. "default")
#
def get_pool project_id:, location:, pool_id:
  # Create a Live Stream client.
  client = Google::Cloud::Video::LiveStream.livestream_service

  # Build the resource name of the pool.
  name = client.pool_path project: project_id, location: location, pool: pool_id

  # Get the pool.
  pool = client.get_pool name: name

  # Print the pool name.
  puts "Pool: #{pool.name}"
end

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器