Obtén un evento de canal

Obtén detalles sobre un recurso de eventos de canal de transmisión en vivo.

Explora más

Para obtener documentación en la que se incluye esta muestra de código, consulta lo siguiente:

Muestra de código

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. Si quieres obtener más información, consulta la documentación de referencia de la API de C# de la API de Live Stream.

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 GetChannelEventSample
{
    public Event GetChannelEvent(
         string projectId, string locationId, string channelId, string eventId)
    {
        // Create the client.
        LivestreamServiceClient client = LivestreamServiceClient.Create();

        GetEventRequest request = new GetEventRequest
        {
            EventName = EventName.FromProjectLocationChannelEvent(projectId, locationId, channelId, eventId),
        };

        // Make the request.
        Event response = client.GetEvent(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. Si quieres obtener más información, consulta la documentación de referencia de la API de Go de la API de Live Stream.

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

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

	req := &livestreampb.GetEventRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/channels/%s/events/%s", projectID, location, channelID, eventID),
	}

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

	fmt.Fprintf(w, "Channel event: %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. Si quieres obtener más información, consulta la documentación de referencia de la API de Java de la API de Live Stream.

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.Event;
import com.google.cloud.video.livestream.v1.EventName;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import java.io.IOException;

public class GetChannelEvent {

  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 channelId = "my-channel-id";
    String eventId = "my-channel-event-id";

    getChannelEvent(projectId, location, channelId, eventId);
  }

  public static void getChannelEvent(
      String projectId, String location, String channelId, String eventId) 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()) {
      EventName name = EventName.of(projectId, location, channelId, eventId);
      Event response = livestreamServiceClient.getEvent(name);
      System.out.println("Channel event: " + 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. Si quieres obtener más información, consulta la documentación de referencia de la API de Node.js de la API de Live Stream.

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';
// channelId = 'my-channel';
// eventId = 'my-channel-event';

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

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

async function getChannelEvent() {
  // Construct request
  const request = {
    name: livestreamServiceClient.eventPath(
      projectId,
      location,
      channelId,
      eventId
    ),
  };
  const [event] = await livestreamServiceClient.getEvent(request);
  console.log(`Channel event: ${event.name}`);
}

getChannelEvent();

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. Si quieres obtener más información, consulta la documentación de referencia de la API de PHP de la API de Live Stream.

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\GetEventRequest;

/**
 * Gets a channel event.
 *
 * @param string  $callingProjectId   The project ID to run the API call under
 * @param string  $location           The location of the channel
 * @param string  $channelId          The ID of the channel
 * @param string  $eventId            The ID of the channel event
 */
function get_channel_event(
    string $callingProjectId,
    string $location,
    string $channelId,
    string $eventId
): void {
    // Instantiate a client.
    $livestreamClient = new LivestreamServiceClient();
    $formattedName = $livestreamClient->eventName($callingProjectId, $location, $channelId, $eventId);

    // Get the channel event.
    $request = (new GetEventRequest())
        ->setName($formattedName);
    $response = $livestreamClient->getEvent($request);
    printf('Channel event: %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. Si quieres obtener más información, consulta la documentación de referencia de la API de Python de la API de Live Stream.

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_channel_event(
    project_id: str, location: str, channel_id: str, event_id: str
) -> live_stream_v1.types.Event:
    """Gets a channel.
    Args:
        project_id: The GCP project ID.
        location: The location of the channel.
        channel_id: The user-defined channel ID.
        event_id: The user-defined event ID."""

    client = LivestreamServiceClient()

    name = f"projects/{project_id}/locations/{location}/channels/{channel_id}/events/{event_id}"
    response = client.get_event(name=name)
    print(f"Channel event: {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. Si quieres obtener más información, consulta la documentación de referencia de la API de Ruby de la API de Live Stream.

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 a channel event
#
# @param project_id [String] Your Google Cloud project (e.g. "my-project")
# @param location [String] The location (e.g. "us-central1")
# @param channel_id [String] Your channel name (e.g. "my-channel")
# @param event_id [String] Your event name (e.g. "my-event")
#
def get_channel_event project_id:, location:, channel_id:, event_id:
  # Create a Live Stream client.
  client = Google::Cloud::Video::LiveStream.livestream_service

  # Build the resource name of the channel event.
  name = client.event_path project: project_id, location: location, channel: channel_id, event: event_id

  # Get the channel event.
  event = client.get_event name: name

  # Print the channel event name.
  puts "Channel event: #{event.name}"
end

¿Qué sigue?

Para buscar y filtrar muestras de código para otros productos de Google Cloud, consulta el navegador de muestra de Google Cloud.