Get asset (v1)

Retrieve an existing asset resource.

Code sample

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"
	livestreampb "cloud.google.com/go/video/livestream/apiv1/livestreampb"
)

// getAsset retrieves an existing asset resource.
func getAsset(ctx context.Context, w io.Writer, projectID string, locationID string, assetID string) error {
	name := fmt.Sprintf("projects/%s/locations/%s/assets/%s", projectID, locationID, assetID)

	client, err := livestream.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("livestream.NewClient: %w", err)
	}
	defer client.Close()

	req := &livestreampb.GetAssetRequest{
		Name: name,
	}

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

	fmt.Fprintf(w, "Retrieved asset: %s\n", response.GetName())
	return nil
}

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.

from google.api_core import exceptions
from google.cloud.video import live_stream_v1


def get_asset(project_id: str, location_id: str, asset_id: str) -> None:
    """Gets a livestream asset.

    Args:
        project_id: The Google Cloud project ID (for example, 'example-project-id').
        location_id: The Google Cloud region where the service is located (for example, 'us-central1').
        asset_id: The ID of the asset (for example, 'example-asset-id').
    """
    client = live_stream_v1.LivestreamServiceClient()

    name = client.asset_path(project_id, location_id, asset_id)

    try:
        response = client.get_asset(name=name)
        print(f"Asset name: {response.name}")
        print(f"Asset state: {response.state.name}")
    except exceptions.GoogleAPICallError as error:
        print(f"Failed to get asset: {error}")

What's next

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