Crea y administra recursos

En esta página, se muestra cómo crear y administrar los recursos de la API de Live Stream. Recursos son imágenes o videos que se pueden utilizar con la API de Live Stream. Puedes usar un recurso para Insertar una cortinilla de video en una transmisión en vivo.

Formatos multimedia compatibles

La API de Live Stream admite los siguientes códecs y formatos de contenido multimedia para elementos.

Medios de entradaFormatos admitidos
Formatos de archivo de videoMP4, MPEG-TS y FLV
Códecs de videoH.264
Códecs de audioAAC, AC3, MP2 y MP3
Formatos de archivo de imagenJPG
Tamaño máximo250 MB
Resoluciones máximas1920 × 1080

Configura el proyecto de Google Cloud y la autenticación

Si no creaste un Proyecto de Google Cloud y credenciales, consulta Antes de comenzar.

Crea un recurso

Para crear un recurso, utiliza el projects.locations.assets.create. El siguiente ejemplo crea un activo de video.

REST

Antes de usar cualquiera de los datos de solicitud a continuación, realiza los siguientes reemplazos:

  • PROJECT_NUMBER: Es tu proyecto de Google Cloud. número; se encuentra en el campo Número de proyecto de la Página Configuración de IAM
  • LOCATION: Es la ubicación en la que se creará el elemento. asset; usa una de las regiones admitidas
    Mostrar ubicaciones
    • us-central1
    • us-east1
    • us-east4
    • us-west1
    • us-west2
    • northamerica-northeast1
    • southamerica-east1
    • asia-east1
    • asia-east2
    • asia-northeast1
    • asia-southeast1
    • australia-southeast1
    • europe-west1
    • europe-west2
    • europe-west3
    • europe-west4
  • ASSET_ID: Un identificador definido por el usuario para el nuevo recurso para crear. Este valor debe tener entre 1 y 63 caracteres, comenzar y terminar con [a-z0-9], y puede contener guiones (-) entre los caracteres. Por ejemplo, my-asset.
  • ASSET_URI: Es el URI del video en tu de bucket de Cloud Storage para usar, como gs://my-bucket/my-video.mp4 (consulta la formatos multimedia compatibles)

Para enviar tu solicitud, expande una de estas opciones:

Deberías recibir una respuesta JSON similar a la que se muestra a continuación:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata",
    "createTime": CREATE_TIME,
    "target": "projects/PROJECT_NUMBER/locations/LOCATION/assets/ASSET_ID",
    "verb": "create",
    "requestedCancellation": false,
    "apiVersion": "v1"
  },
  "done": false
}
Este comando crea una operación de larga duración (LRO) que puedes usar para realizar un seguimiento del progreso de tu solicitud. Consulta Administra operaciones de larga duración para obtener más información.

C#

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream C# API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.


using Google.Api.Gax.ResourceNames;
using Google.Cloud.Video.LiveStream.V1;
using Google.LongRunning;
using System.Threading.Tasks;

public class CreateAssetSample
{
    public async Task<Asset> CreateAssetAsync(
         string projectId, string locationId, string assetId, string assetUri)
    {
        // Create the client.
        LivestreamServiceClient client = LivestreamServiceClient.Create();

        CreateAssetRequest request = new CreateAssetRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation(projectId, locationId),
            AssetId = assetId,
            Asset = new Asset
            {
                Video = new Asset.Types.VideoAsset
                {
                    Uri = assetUri
                }
            }
        };

        // Make the request.
        Operation<Asset, OperationMetadata> response = await client.CreateAssetAsync(request);

        // Poll until the returned long-running operation is complete.
        Operation<Asset, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result.
        return completedResponse.Result;
    }
}

Go

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Go API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

import (
	"context"
	"fmt"
	"io"

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

// createAsset creates an asset. This asset references a video file
// in Cloud Storage.
func createAsset(w io.Writer, projectID, location, assetID, assetURI string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// assetID := "my-asset"
	// assetURI := "gs://my-bucket/my-video.mp4"
	ctx := context.Background()
	client, err := livestream.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer client.Close()

	req := &livestreampb.CreateAssetRequest{
		Parent:  fmt.Sprintf("projects/%s/locations/%s", projectID, location),
		AssetId: assetID,
		Asset: &livestreampb.Asset{
			Resource: &livestreampb.Asset_Video{
				Video: &livestreampb.Asset_VideoAsset{
					Uri: assetURI,
				},
			},
		},
	}
	// Creates the asset.
	op, err := client.CreateAsset(ctx, req)
	if err != nil {
		return fmt.Errorf("CreateAsset: %w", err)
	}
	response, err := op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("Wait: %w", err)
	}

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

Java

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Java API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.


import com.google.cloud.video.livestream.v1.Asset;
import com.google.cloud.video.livestream.v1.Asset.VideoAsset;
import com.google.cloud.video.livestream.v1.CreateAssetRequest;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import com.google.cloud.video.livestream.v1.LocationName;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateAsset {

  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 assetId = "my-asset-id";
    String assetUri = "gs://my-bucket/my-video.mp4";

    createAsset(projectId, location, assetId, assetUri);
  }

  public static void createAsset(String projectId, String location, String assetId, String assetUri)
      throws InterruptedException, ExecutionException, TimeoutException, 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. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create();
    var createAssetRequest =
        CreateAssetRequest.newBuilder()
            .setParent(LocationName.of(projectId, location).toString())
            .setAssetId(assetId)
            .setAsset(
                Asset.newBuilder()
                    .setVideo(
                        VideoAsset.newBuilder()
                            .setUri(assetUri)
                            .build())
                    .build())
            .build();
    // First API call in a project can take up to 15 minutes.
    Asset result =
        livestreamServiceClient.createAssetAsync(createAssetRequest).get(15, TimeUnit.MINUTES);
    System.out.println("Asset: " + result.getName());
    livestreamServiceClient.close();
  }
}

Node.js

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Node.js API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// projectId = 'my-project-id';
// location = 'us-central1';
// assetId = 'my-asset';
// assetUri = 'gs://my-bucket/my-video.mp4';

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

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

async function createAsset() {
  // Construct request
  const request = {
    parent: livestreamServiceClient.locationPath(projectId, location),
    assetId: assetId,
    asset: {
      video: {
        uri: assetUri,
      },
    },
  };

  // Run request
  const [operation] = await livestreamServiceClient.createAsset(request);
  const response = await operation.promise();
  const [asset] = response;
  console.log(`Asset: ${asset.name}`);
}

createAsset();

PHP

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream PHP API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

use Google\Cloud\Video\LiveStream\V1\Asset;
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\CreateAssetRequest;

/**
 * Creates an asset. You can use an asset to create a slate.
 *
 * @param string  $callingProjectId   The project ID to run the API call under
 * @param string  $location           The location of the asset
 * @param string  $assetId            The ID of the asset to be created
 * @param string  $assetUri           The Cloud Storage URI of the asset
 */
function create_asset(
    string $callingProjectId,
    string $location,
    string $assetId,
    string $assetUri
): void {
    // Instantiate a client.
    $livestreamClient = new LivestreamServiceClient();

    $parent = $livestreamClient->locationName($callingProjectId, $location);
    $asset = (new Asset())
        ->setVideo(
            (new Asset\VideoAsset())
                ->setUri($assetUri));

    // Run the asset creation request. The response is a long-running operation ID.
    $request = (new CreateAssetRequest())
        ->setParent($parent)
        ->setAsset($asset)
        ->setAssetId($assetId);
    $operationResponse = $livestreamClient->createAsset($request);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
        // Print results
        printf('Asset: %s' . PHP_EOL, $result->getName());
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
}

Python

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Python API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.


import argparse

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


def create_asset(
    project_id: str, location: str, asset_id: str, asset_uri: str
) -> live_stream_v1.types.Asset:
    """Creates an asset.
    Args:
        project_id: The GCP project ID.
        location: The location in which to create the asset.
        asset_id: The user-defined asset ID.
        asset_uri: The asset URI (e.g., 'gs://my-bucket/my-video.mp4')."""

    client = LivestreamServiceClient()

    parent = f"projects/{project_id}/locations/{location}"

    asset = live_stream_v1.types.Asset(
        video=live_stream_v1.types.Asset.VideoAsset(
            uri=asset_uri,
        )
    )
    operation = client.create_asset(parent=parent, asset=asset, asset_id=asset_id)
    response = operation.result(600)
    print(f"Asset: {response.name}")

    return response

Ruby

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Ruby API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

require "google/cloud/video/live_stream"

##
# Create an asset
#
# @param project_id [String] Your Google Cloud project (e.g. "my-project")
# @param location [String] The location (e.g. "us-central1")
# @param asset_id [String] Your asset name (e.g. "my-asset")
# @param asset_uri [String] Your asset URI (e.g. "gs://my-bucket/my-video.mp4")
#
def create_asset project_id:, location:, asset_id:, asset_uri:
  # 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

  # Set the asset fields.
  new_asset = {
    video: {
      uri: asset_uri
    }
  }

  operation = client.create_asset parent: parent, asset: new_asset, asset_id: asset_id

  # The returned object is of type Gapic::Operation. You can use this
  # object to check the status of an operation, cancel it, or wait
  # for results. Here is how to block until completion:
  operation.wait_until_done!

  # Print the asset name.
  puts "Asset: #{operation.response.name}"
end

Obtén detalles de los recursos

Para obtener los detalles del activo, usa el projects.locations.assets.get.

REST

Antes de usar cualquiera de los datos de solicitud a continuación, realiza los siguientes reemplazos:

  • PROJECT_NUMBER: Es tu proyecto de Google Cloud. número; se encuentra en el campo Número de proyecto de la Página Configuración de IAM
  • LOCATION: Es la ubicación de tu recurso. usa uno de las regiones admitidas
    Mostrar ubicaciones
    • us-central1
    • us-east1
    • us-east4
    • us-west1
    • us-west2
    • northamerica-northeast1
    • southamerica-east1
    • asia-east1
    • asia-east2
    • asia-northeast1
    • asia-southeast1
    • australia-southeast1
    • europe-west1
    • europe-west2
    • europe-west3
    • europe-west4
  • ASSET_ID: Es el identificador definido por el usuario para la recurso

Para enviar tu solicitud, expande una de estas opciones:

Deberías recibir una respuesta JSON similar a la que se muestra a continuación:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/assets/ASSET_ID",
  "createTime": CREATE_TIME,
  "updateTime": UPDATE_TIME,
  "video": {
    "uri": "ASSET_URI"
  },
  "crc32c": "pKNslg==",
  "state": "ACTIVE"
}

C#

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream C# API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.


using Google.Cloud.Video.LiveStream.V1;

public class GetAssetSample
{
    public Asset GetAsset(
         string projectId, string locationId, string assetId)
    {
        // Create the client.
        LivestreamServiceClient client = LivestreamServiceClient.Create();

        GetAssetRequest request = new GetAssetRequest
        {
            AssetName = AssetName.FromProjectLocationAsset(projectId, locationId, assetId)
        };

        // Make the request.
        Asset response = client.GetAsset(request);
        return response;
    }
}

Go

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Go API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

import (
	"context"
	"fmt"
	"io"

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

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

	req := &livestreampb.GetAssetRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/assets/%s", projectID, location, assetID),
	}

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

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

Java

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Java API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.


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

public class GetAsset {

  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 assetId = "my-asset-id";

    getAsset(projectId, location, assetId);
  }

  public static void getAsset(String projectId, String location, String assetId)
      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()) {
      AssetName name = AssetName.of(projectId, location, assetId);
      Asset response = livestreamServiceClient.getAsset(name);
      System.out.println("Asset: " + response.getName());
    }
  }
}

Node.js

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Node.js API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

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

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

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

async function getAsset() {
  // Construct request
  const request = {
    name: livestreamServiceClient.assetPath(projectId, location, assetId),
  };
  const [asset] = await livestreamServiceClient.getAsset(request);
  console.log(`Asset: ${asset.name}`);
}

getAsset();

PHP

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream PHP API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

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

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

    // Get the asset.
    $request = (new GetAssetRequest())
        ->setName($formattedName);
    $response = $livestreamClient->getAsset($request);
    // Print results
    printf('Asset: %s' . PHP_EOL, $response->getName());
}

Python

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Python API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.


import argparse

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


def get_asset(
    project_id: str, location: str, asset_id: str
) -> live_stream_v1.types.Asset:
    """Gets an asset.
    Args:
        project_id: The GCP project ID.
        location: The location of the asset.
        asset_id: The user-defined asset ID."""

    client = LivestreamServiceClient()

    name = f"projects/{project_id}/locations/{location}/assets/{asset_id}"
    response = client.get_asset(name=name)
    print(f"Asset: {response.name}")

    return response

Ruby

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Ruby API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

require "google/cloud/video/live_stream"

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

  # Build the resource name of the asset.
  name = client.asset_path project: project_id, location: location, asset: asset_id

  # Get the asset.
  asset = client.get_asset name: name

  # Print the asset name.
  puts "Asset: #{asset.name}"
end

Enumerar recursos

Para enumerar todos los recursos que creaste en una ubicación, usa el projects.locations.assets.list.

REST

Antes de usar cualquiera de los datos de solicitud a continuación, realiza los siguientes reemplazos:

  • PROJECT_NUMBER: Es tu proyecto de Google Cloud. número; se encuentra en el campo Número de proyecto de la Página Configuración de IAM
  • LOCATION: La ubicación de tus recursos. usa uno de las regiones admitidas
    Mostrar ubicaciones
    • us-central1
    • us-east1
    • us-east4
    • us-west1
    • us-west2
    • northamerica-northeast1
    • southamerica-east1
    • asia-east1
    • asia-east2
    • asia-northeast1
    • asia-southeast1
    • australia-southeast1
    • europe-west1
    • europe-west2
    • europe-west3
    • europe-west4

Para enviar tu solicitud, expande una de estas opciones:

Deberías recibir una respuesta JSON similar a la que se muestra a continuación:

{
  "assets": [
    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/assets/ASSET_ID",
      "createTime": CREATE_TIME,
      "updateTime": UPDATE_TIME,
      "video": {
        "uri": "ASSET_URI"
      },
      "crc32c": "pKNslg==",
      "state": "ACTIVE"
    },
    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/assets/my-other-asset",
      "createTime": CREATE_TIME,
      "updateTime": UPDATE_TIME,
      "video": {
        "uri": "my-other-asset-uri"
      },
      "crc32c": "pLNslg==",
      "state": "ACTIVE"
    }
  ]
}

C#

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream C# API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo 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 obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Go API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo 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 obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Java API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo 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 obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Node.js API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo 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 obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream PHP API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo 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 obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Python API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo 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 obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Ruby API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo 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

Cómo borrar un recurso

Para eliminar un recurso, utiliza el projects.locations.assets.delete.

REST

Antes de usar cualquiera de los datos de solicitud a continuación, realiza los siguientes reemplazos:

  • PROJECT_NUMBER: Es tu proyecto de Google Cloud. número; se encuentra en el campo Número de proyecto de la Página Configuración de IAM
  • LOCATION: Es la ubicación de tu recurso. usa uno de las regiones admitidas
    Mostrar ubicaciones
    • us-central1
    • us-east1
    • us-east4
    • us-west1
    • us-west2
    • northamerica-northeast1
    • southamerica-east1
    • asia-east1
    • asia-east2
    • asia-northeast1
    • asia-southeast1
    • australia-southeast1
    • europe-west1
    • europe-west2
    • europe-west3
    • europe-west4
  • ASSET_ID: Es el identificador definido por el usuario para la recurso

Para enviar tu solicitud, expande una de estas opciones:

Deberías recibir una respuesta JSON similar a la que se muestra a continuación:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata",
    "createTime": CREATE_TIME,
    "target": "projects/PROJECT_NUMBER/locations/LOCATION/assets/ASSET_ID",
    "verb": "delete",
    "requestedCancellation": false,
    "apiVersion": "v1"
  },
  "done": false
}
Este comando crea una operación de larga duración (LRO) que puedes usar para realizar un seguimiento del progreso de tu solicitud. Consulta Administra operaciones de larga duración para obtener más información.

C#

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream C# API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.


using Google.Cloud.Video.LiveStream.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;
using System.Threading.Tasks;

public class DeleteAssetSample
{
    public async Task DeleteAssetAsync(
         string projectId, string locationId, string assetId)
    {
        // Create the client.
        LivestreamServiceClient client = LivestreamServiceClient.Create();

        DeleteAssetRequest request = new DeleteAssetRequest
        {
            AssetName = AssetName.FromProjectLocationAsset(projectId, locationId, assetId)
        };

        // Make the request.
        Operation<Empty, OperationMetadata> response = await client.DeleteAssetAsync(request);

        // Poll until the returned long-running operation is complete.
        await response.PollUntilCompletedAsync();
    }
}

Go

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Go API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

import (
	"context"
	"fmt"
	"io"

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

// deleteAsset deletes a previously-created asset.
func deleteAsset(w io.Writer, projectID, location, assetID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// assetID := "my-asset"
	ctx := context.Background()
	client, err := livestream.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer client.Close()

	req := &livestreampb.DeleteAssetRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/assets/%s", projectID, location, assetID),
	}

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

	fmt.Fprintf(w, "Deleted asset")
	return nil
}

Java

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Java API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.


import com.google.cloud.video.livestream.v1.AssetName;
import com.google.cloud.video.livestream.v1.DeleteAssetRequest;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class DeleteAsset {

  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 assetId = "my-asset-id";

    deleteAsset(projectId, location, assetId);
  }

  public static void deleteAsset(String projectId, String location, String assetId)
      throws InterruptedException, ExecutionException, TimeoutException, 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. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create();
    var deleteAssetRequest =
        DeleteAssetRequest.newBuilder()
            .setName(AssetName.of(projectId, location, assetId).toString())
            .build();
    // First API call in a project can take up to 10 minutes.
    livestreamServiceClient.deleteAssetAsync(deleteAssetRequest).get(10, TimeUnit.MINUTES);
    System.out.println("Deleted asset");
    livestreamServiceClient.close();
  }
}

Node.js

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Node.js API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

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

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

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

async function deleteAsset() {
  // Construct request
  const request = {
    name: livestreamServiceClient.assetPath(projectId, location, assetId),
  };

  // Run request
  const [operation] = await livestreamServiceClient.deleteAsset(request);
  await operation.promise();
  console.log('Deleted asset');
}

deleteAsset();

PHP

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream PHP API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

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

/**
 * Deletes an asset.
 *
 * @param string  $callingProjectId   The project ID to run the API call under
 * @param string  $location           The location of the asset
 * @param string  $assetId            The ID of the asset to be deleted
 */
function delete_asset(
    string $callingProjectId,
    string $location,
    string $assetId
): void {
    // Instantiate a client.
    $livestreamClient = new LivestreamServiceClient();
    $formattedName = $livestreamClient->assetName($callingProjectId, $location, $assetId);

    // Run the asset deletion request. The response is a long-running operation ID.
    $request = (new DeleteAssetRequest())
        ->setName($formattedName);
    $operationResponse = $livestreamClient->deleteAsset($request);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        // Print status
        printf('Deleted asset %s' . PHP_EOL, $assetId);
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
}

Python

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Python API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.


import argparse

from google.cloud.video.live_stream_v1.services.livestream_service import (
    LivestreamServiceClient,
)
from google.protobuf import empty_pb2 as empty


def delete_asset(project_id: str, location: str, asset_id: str) -> empty.Empty:
    """Deletes an asset.
    Args:
        project_id: The GCP project ID.
        location: The location of the asset.
        asset_id: The user-defined asset ID."""

    client = LivestreamServiceClient()

    name = f"projects/{project_id}/locations/{location}/assets/{asset_id}"
    operation = client.delete_asset(name=name)
    response = operation.result(600)
    print("Deleted asset")

    return response

Ruby

Para obtener información sobre cómo instalar y usar la biblioteca cliente de la API de Live Stream, consulta Bibliotecas cliente de la API de Live Stream. Para obtener más información, consulta la API de Live Stream Ruby API documentación de referencia.

Para autenticarte en la API de Live Stream, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.

require "google/cloud/video/live_stream"

##
# Delete an asset
#
# @param project_id [String] Your Google Cloud project (e.g. "my-project")
# @param location [String] The location (e.g. "us-central1")
# @param asset_id [String] Your asset name (e.g. "my-asset")
#
def delete_asset project_id:, location:, asset_id:
  # Create a Live Stream client.
  client = Google::Cloud::Video::LiveStream.livestream_service

  # Build the resource name of the asset.
  name = client.asset_path project: project_id, location: location, asset: asset_id

  # Delete the asset.
  operation = client.delete_asset name: name

  # The returned object is of type Gapic::Operation. You can use this
  # object to check the status of an operation, cancel it, or wait
  # for results. Here is how to block until completion:
  operation.wait_until_done!

  # Print a success message.
  puts "Deleted asset"
end