List inputs (v1)

List all inputs in a given location.

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"
	"google.golang.org/api/iterator"
)

// listInputs lists all channel inputs in a given location.
func listInputs(ctx context.Context, w io.Writer, projectID string, locationID string) error {
	parent := fmt.Sprintf("projects/%s/locations/%s", projectID, locationID)

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

	req := &livestreampb.ListInputsRequest{
		Parent: parent,
	}

	it := client.ListInputs(ctx, req)
	for {
		input, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("ListInputs iteration failed: %w", err)
		}
		fmt.Fprintf(w, "Input: %s\n", input.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.

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


def list_inputs(project_id: str, location_id: str) -> None:
    """Lists livestream inputs in a Google Cloud region.

    Args:
        project_id: The Google Cloud project ID.
        location_id: The Google Cloud region (for example, "us-central1") where
          Livestream inputs reside.
    """
    client = live_stream_v1.LivestreamServiceClient()
    parent = f"projects/{project_id}/locations/{location_id}"

    try:
        response = client.list_inputs(parent=parent)
        for live_input in response:
            print(f"Input name: {live_input.name}")
    except google.api_core.exceptions.GoogleAPICallError as error:
        print(f"API request failed: {error}")

What's next

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