Get a pool

Get details for a live stream pool resource.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

C#

To learn how to install and use the client library for Live Stream API, see Live Stream API client libraries. For more information, see the Live Stream API C# API reference documentation.

To authenticate to Live Stream API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


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

To learn how to install and use the client library for Live Stream API, see Live Stream API client libraries. For more information, see the Live Stream API Go API reference documentation.

To authenticate to Live Stream API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

To learn how to install and use the client library for Live Stream API, see Live Stream API client libraries. For more information, see the Live Stream API Java API reference documentation.

To authenticate to Live Stream API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


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

To learn how to install and use the client library for Live Stream API, see Live Stream API client libraries. For more information, see the Live Stream API Node.js API reference documentation.

To authenticate to Live Stream API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

/**
 * 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

To learn how to install and use the client library for Live Stream API, see Live Stream API client libraries. For more information, see the Live Stream API PHP API reference documentation.

To authenticate to Live Stream API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

To learn how to install and use the client library for Live Stream API, see Live Stream API client libraries. For more information, see the Live Stream API Python API reference documentation.

To authenticate to Live Stream API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


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

To learn how to install and use the client library for Live Stream API, see Live Stream API client libraries. For more information, see the Live Stream API Ruby API reference documentation.

To authenticate to Live Stream API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.