Listar recursos

Liste todos os recursos de transmissão ao vivo de um local.

Mais informações

Para ver a documentação detalhada que inclui este exemplo de código, consulte:

Exemplo de código

C#

Para saber como instalar e usar a biblioteca de cliente da API Live Stream, consulte Bibliotecas de cliente da API Live Stream. Para mais informações, consulte a documentação de referência da API C# da API Live Stream.

Para autenticar na API Live Stream, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.


using Google.Api.Gax;
using Google.Api.Gax.ResourceNames;
using Google.Cloud.Video.LiveStream.V1;
using System.Collections.Generic;
using System.Linq;

public class ListAssetsSample
{
    public IList<Asset> ListAssets(
        string projectId, string regionId)
    {
        // Create the client.
        LivestreamServiceClient client = LivestreamServiceClient.Create();

        ListAssetsRequest request = new ListAssetsRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation(projectId, regionId)
        };

        // Make the request.
        PagedEnumerable<ListAssetsResponse, Asset> response = client.ListAssets(request);

        // The returned sequence will lazily perform RPCs as it's being iterated over.
        return response.ToList();
    }
}

Go

Para saber como instalar e usar a biblioteca de cliente da API Live Stream, consulte Bibliotecas de cliente da API Live Stream. Para mais informações, consulte a documentação de referência da API Go da API Live Stream.

Para autenticar na API Live Stream, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.

import (
	"context"
	"fmt"
	"io"

	"google.golang.org/api/iterator"

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

// listAssets lists all assets for a given location.
func listAssets(w io.Writer, projectID, location string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	ctx := context.Background()
	client, err := livestream.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer client.Close()

	req := &livestreampb.ListAssetsRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location),
	}

	it := client.ListAssets(ctx, req)
	fmt.Fprintln(w, "Assets:")

	for {
		response, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("ListAssets: %w", err)
		}
		fmt.Fprintln(w, response.GetName())
	}
	return nil
}

Java

Para saber como instalar e usar a biblioteca de cliente da API Live Stream, consulte Bibliotecas de cliente da API Live Stream. Para mais informações, consulte a documentação de referência da API Java da API Live Stream.

Para autenticar na API Live Stream, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.


import com.google.cloud.video.livestream.v1.Asset;
import com.google.cloud.video.livestream.v1.ListAssetsRequest;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import com.google.cloud.video.livestream.v1.LocationName;
import java.io.IOException;

public class ListAssets {

  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";

    listAssets(projectId, location);
  }

  public static void listAssets(String projectId, String location) 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()) {
      var listAssetsRequest =
          ListAssetsRequest.newBuilder()
              .setParent(LocationName.of(projectId, location).toString())
              .build();

      LivestreamServiceClient.ListAssetsPagedResponse response =
          livestreamServiceClient.listAssets(listAssetsRequest);
      System.out.println("Assets:");

      for (Asset asset : response.iterateAll()) {
        System.out.println(asset.getName());
      }
    }
  }
}

Node.js

Para saber como instalar e usar a biblioteca de cliente da API Live Stream, consulte Bibliotecas de cliente da API Live Stream. Para mais informações, consulte a documentação de referência da API Node.js da API Live Stream.

Para autenticar na API Live Stream, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.

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

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

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

async function listAssets() {
  const iterable = await livestreamServiceClient.listAssetsAsync({
    parent: livestreamServiceClient.locationPath(projectId, location),
  });
  console.info('Assets:');
  for await (const response of iterable) {
    console.log(response.name);
  }
}

listAssets();

PHP

Para saber como instalar e usar a biblioteca de cliente da API Live Stream, consulte Bibliotecas de cliente da API Live Stream. Para mais informações, consulte a documentação de referência da API PHP da API Live Stream.

Para autenticar na API Live Stream, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.

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

/**
 * Lists the assets for a given location.
 *
 * @param string  $callingProjectId   The project ID to run the API call under
 * @param string  $location           The location of the assets
 */
function list_assets(
    string $callingProjectId,
    string $location
): void {
    // Instantiate a client.
    $livestreamClient = new LivestreamServiceClient();
    $parent = $livestreamClient->locationName($callingProjectId, $location);
    $request = (new ListAssetsRequest())
        ->setParent($parent);

    $response = $livestreamClient->listAssets($request);
    // Print the asset list.
    $assets = $response->iterateAllElements();
    print('Assets:' . PHP_EOL);
    foreach ($assets as $asset) {
        printf('%s' . PHP_EOL, $asset->getName());
    }
}

Python

Para saber como instalar e usar a biblioteca de cliente da API Live Stream, consulte Bibliotecas de cliente da API Live Stream. Para mais informações, consulte a documentação de referência da API Python da API Live Stream.

Para autenticar na API Live Stream, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.


import argparse

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

def list_assets(project_id: str, location: str) -> pagers.ListAssetsPager:
    """Lists all assets in a location.
    Args:
        project_id: The GCP project ID.
        location: The location of the assets."""

    client = LivestreamServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    page_result = client.list_assets(parent=parent)
    print("Assets:")

    responses = []
    for response in page_result:
        print(response.name)
        responses.append(response)

    return responses

Ruby

Para saber como instalar e usar a biblioteca de cliente da API Live Stream, consulte Bibliotecas de cliente da API Live Stream. Para mais informações, consulte a documentação de referência da API Ruby da API Live Stream.

Para autenticar na API Live Stream, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.

require "google/cloud/video/live_stream"

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

  # Build the resource name of the parent.
  parent = client.location_path project: project_id, location: location

  # Get the list of assets.
  response = client.list_assets parent: parent

  puts "Assets:"
  # Print out all assets.
  response.each do |asset|
    puts asset.name
  end
end

A seguir

Para pesquisar e filtrar amostras de código para outros produtos do Google Cloud, consulte o navegador de amostra do Google Cloud.