Creazione e gestione degli eventi del canale

Questa pagina mostra come creare e gestire gli eventi del canale dell'API Live Stream. Un evento canale è una risorsa secondaria di un canale. Puoi usare un evento canale per eseguire operazioni su una risorsa canale senza dover arrestare il canale.

Configura il progetto Google Cloud e l'autenticazione

Se non hai creato un progetto Google Cloud e le credenziali, consulta Prima di iniziare.

Prerequisiti

Prima di creare un evento del canale, devi creare le seguenti risorse:

  1. Crea un endpoint di input

  2. Creare un canale

Creare un evento del canale

Assicurati di avviare il canale prima di creare un evento del canale.

Per creare un evento del canale, usa il metodo projects.locations.channels.events.create. Sono supportati i seguenti tipi di eventi:

Gli eventi possono essere eseguiti immediatamente o pianificati per l'esecuzione in futuro.

L'API Live Stream elimina automaticamente un evento del canale sette giorni dopo l'esecuzione. Questa eliminazione include gli eventi non riusciti.

Evento di interruzione pubblicitaria

Utilizza l'oggetto adBreak per inserire una nuova opportunità di annuncio.

Utilizza l'evento Torna al programma per tornare dall'interruzione pubblicitaria al live streaming.

REST

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_NUMBER: il numero del tuo progetto Google Cloud, disponibile nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui si trova il tuo canale; utilizza una delle regioni supportate.
    Mostra località
    • 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
  • CHANNEL_ID: un identificatore del canale definito dall'utente.
  • EVENT_ID: un identificatore dell'evento definito dall'utente.

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID/events/EVENT_ID",
  "createTime": CREATE_TIME,
  "updateTime": UPDATE_TIME,
  "adBreak": {
    "duration": "100s"
  },
  "executeNow": true,
  "state": "PENDING"
}

C#

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API C# per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


using Google.Cloud.Video.LiveStream.V1;

public class CreateChannelEventSample
{
    public Event CreateChannelEvent(
         string projectId, string locationId, string channelId, string eventId)
    {
        // Create the client.
        LivestreamServiceClient client = LivestreamServiceClient.Create();

        CreateEventRequest request = new CreateEventRequest
        {
            ParentAsChannelName = ChannelName.FromProjectLocationChannel(projectId, locationId, channelId),
            EventId = eventId,
            Event = new Event
            {
                AdBreak = new Event.Types.AdBreakTask
                {
                    Duration = new Google.Protobuf.WellKnownTypes.Duration
                    {
                        Seconds = 30
                    }
                },
                ExecuteNow = true
            }
        };

        // Make the request.
        Event response = client.CreateEvent(request);
        return response;
    }
}

Go

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Go per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

import (
	"context"
	"fmt"
	"io"

	"github.com/golang/protobuf/ptypes/duration"

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

// createChannelEvent creates a channel event. An event is a sub-resource of a
// channel, which can be scheduled by the user to execute operations on a
// channel resource without having to stop the channel. This sample creates an
// ad break event.
func createChannelEvent(w io.Writer, projectID, location, channelID, eventID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// channelID := "my-channel"
	// 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.CreateEventRequest{
		Parent:  fmt.Sprintf("projects/%s/locations/%s/channels/%s", projectID, location, channelID),
		EventId: eventID,
		Event: &livestreampb.Event{
			Task: &livestreampb.Event_AdBreak{
				AdBreak: &livestreampb.Event_AdBreakTask{
					Duration: &duration.Duration{
						Seconds: 30,
					},
				},
			},
			ExecuteNow: true,
		},
	}
	// Creates the channel event.
	response, err := client.CreateEvent(ctx, req)
	if err != nil {
		return fmt.Errorf("CreateEvent: %w", err)
	}

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

Java

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Java per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


import com.google.cloud.video.livestream.v1.ChannelName;
import com.google.cloud.video.livestream.v1.CreateEventRequest;
import com.google.cloud.video.livestream.v1.Event;
import com.google.cloud.video.livestream.v1.Event.AdBreakTask;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import com.google.protobuf.Duration;
import java.io.IOException;

public class CreateChannelEvent {

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

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

  public static void createChannelEvent(
      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()) {
      var createEventRequest =
          CreateEventRequest.newBuilder()
              .setParent(ChannelName.of(projectId, location, channelId).toString())
              .setEventId(eventId)
              .setEvent(
                  Event.newBuilder()
                      .setAdBreak(
                          AdBreakTask.newBuilder()
                              .setDuration(Duration.newBuilder().setSeconds(30).build())
                              .build())
                      .setExecuteNow(true)
                      .build())
              .build();

      Event response = livestreamServiceClient.createEvent(createEventRequest);
      System.out.println("Channel event: " + response.getName());
    }
  }
}

Node.js

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Node.js per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

/**
 * 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 createChannelEvent() {
  // Construct request
  const request = {
    parent: livestreamServiceClient.channelPath(
      projectId,
      location,
      channelId
    ),
    eventId: eventId,
    event: {
      adBreak: {
        duration: {
          seconds: 30,
        },
      },
      executeNow: true,
    },
  };

  // Run request
  const [event] = await livestreamServiceClient.createEvent(request);
  console.log(`Channel event: ${event.name}`);
}

createChannelEvent();

PHP

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API PHP per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

use Google\Cloud\Video\LiveStream\V1\Event;
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\CreateEventRequest;
use Google\Protobuf\Duration;

/**
 * Creates a channel event. This particular sample inserts an ad break marker.
 * Other event types are supported.
 *
 * @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 create_channel_event(
    string $callingProjectId,
    string $location,
    string $channelId,
    string $eventId
): void {
    // Instantiate a client.
    $livestreamClient = new LivestreamServiceClient();

    $parent = $livestreamClient->channelName($callingProjectId, $location, $channelId);

    $eventAdBreak = (new Event\AdBreakTask())
        ->setDuration(new Duration(['seconds' => 30]));
    $event = (new Event())
        ->setAdBreak($eventAdBreak)
        ->setExecuteNow(true);

    // Run the channel event creation request.
    $request = (new CreateEventRequest())
        ->setParent($parent)
        ->setEvent($event)
        ->setEventId($eventId);
    $response = $livestreamClient->createEvent($request);
    // Print results.
    printf('Channel event: %s' . PHP_EOL, $response->getName());
}

Python

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Python per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


import argparse

from google.cloud.video import live_stream_v1
from google.cloud.video.live_stream_v1.services.livestream_service import (
    LivestreamServiceClient,
)
from google.protobuf import duration_pb2 as duration

def create_channel_event(
    project_id: str, location: str, channel_id: str, event_id: str
) -> live_stream_v1.types.Event:
    """Creates a channel event.
    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()
    parent = f"projects/{project_id}/locations/{location}/channels/{channel_id}"
    name = f"projects/{project_id}/locations/{location}/channels/{channel_id}/events/{event_id}"

    event = live_stream_v1.types.Event(
        name=name,
        ad_break=live_stream_v1.types.Event.AdBreakTask(
            duration=duration.Duration(
                seconds=30,
            ),
        ),
        execute_now=True,
    )

    response = client.create_event(parent=parent, event=event, event_id=event_id)
    print(f"Channel event: {response.name}")

    return response

Ruby

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Ruby per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

require "google/cloud/video/live_stream"

##
# Create 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 create_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 parent.
  parent = client.channel_path project: project_id, location: location, channel: channel_id

  # Set the event fields.
  new_event = {
    ad_break: {
      duration: {
        seconds: 100
      }
    },
    execute_now: true
  }

  response = client.create_event parent: parent, event: new_event, event_id: event_id

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

Inserisci evento slate

Usa l'oggetto slate per inserire uno slate in un live streaming.

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_NUMBER: il numero del tuo progetto Google Cloud, disponibile nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui si trova il tuo canale; utilizza una delle regioni supportate.
    Mostra località
    • 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
  • CHANNEL_ID: un identificatore del canale definito dall'utente.
  • EVENT_ID: un identificatore dell'evento definito dall'utente.
  • ASSET_ID: identificatore definito dall'utente per la risorsa di slate

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID/events/EVENT_ID",
  "createTime": CREATE_TIME,
  "updateTime": UPDATE_TIME,
  "slate": {
    "duration": "60s",
    "asset": "projects/PROJECT_NUMBER/locations/LOCATION/assets/ASSET_ID"
  },
  "executeNow": "true",
  "state": "PENDING"
}

Torna all'evento del programma

Utilizza l'oggetto returnToProgram per interrompere tutti gli eventi adBreak in esecuzione. Puoi interrompere questi eventi immediatamente o pianificare l'interruzione per un momento futuro utilizzando il campo executionTime.

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_NUMBER: il numero del tuo progetto Google Cloud, disponibile nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui si trova il tuo canale; utilizza una delle regioni supportate.
    Mostra località
    • 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
  • CHANNEL_ID: un identificatore del canale definito dall'utente.
  • EVENT_ID: un identificatore dell'evento definito dall'utente.

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID/events/EVENT_ID",
  "createTime": CREATE_TIME,
  "updateTime": UPDATE_TIME,
  "executeNow": true,
  "state": "PENDING",
  "returnToProgram": {}
}

Disattiva evento

Utilizza l'oggetto mute per disattivare l'audio del live streaming. Puoi specificare una durata per cui l'audio dello stream deve essere disattivato o puoi disattivare l'audio dello stream fino a quando non viene eseguito un evento di riattivazione dell'audio.

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_NUMBER: il numero del tuo progetto Google Cloud, disponibile nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui si trova il tuo canale; utilizza una delle regioni supportate.
    Mostra località
    • 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
  • CHANNEL_ID: un identificatore del canale definito dall'utente.
  • EVENT_ID: un identificatore dell'evento definito dall'utente.

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID/events/EVENT_ID",
  "createTime": CREATE_TIME,
  "updateTime": UPDATE_TIME,
  "mute": {
    "duration": "30s"
  },
  "executeNow": true,
  "state": "PENDING"
}

Riattiva evento

Utilizza l'oggetto unmute per riattivare l'audio del live streaming, ovvero ripristinare l'audio.

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_NUMBER: il numero del tuo progetto Google Cloud, disponibile nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui si trova il tuo canale; utilizza una delle regioni supportate.
    Mostra località
    • 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
  • CHANNEL_ID: un identificatore del canale definito dall'utente.
  • EVENT_ID: un identificatore dell'evento definito dall'utente.

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID/events/EVENT_ID",
  "createTime": CREATE_TIME,
  "updateTime": UPDATE_TIME,
  "unmute": {},
  "executeNow": true,
  "state": "PENDING"
}

Cambia evento di input

Utilizza l'oggetto inputSwitch per cambiare manualmente l'input del canale. Per ulteriori informazioni sulla creazione di un canale con input aggiuntivi, consulta Creazione di un canale con uno stream di input di backup.

Quando cambi manualmente l'input, InputSwitchMode diventa MANUAL. Viene quindi sempre utilizzato il flusso di input designato, anche se un flusso di input di backup viene configurato dal campo automaticFailover del flusso di input designato. Il canale non passa allo stream di input di backup quando il flusso di input designato si disconnette perché il failover automatico è disabilitato. Per abilitare nuovamente il failover, consulta Abilitare il failover automatico.

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_NUMBER: il numero del tuo progetto Google Cloud, disponibile nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui si trova il tuo canale; utilizza una delle regioni supportate.
    Mostra località
    • 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
  • CHANNEL_ID: un identificatore del canale definito dall'utente.
  • EVENT_ID: un identificatore dell'evento definito dall'utente.

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID/events/EVENT_ID",
  "createTime": CREATE_TIME,
  "updateTime": UPDATE_TIME,
  "inputSwitch": {
    "inputKey": "input-backup"
  },
  "executeNow": true,
  "state": "PENDING"
}

Abilita il failover automatico

Per abilitare il failover automatico dopo un cambio di input manuale:

  1. Interrompere il canale
  2. Aggiorna il campo del canale InputSwitchMode a FAILOVER_PREFER_PRIMARY
  3. Avvia il canale

Scoprire i dettagli dell'evento del canale

Per visualizzare i dettagli di un evento del canale, usa il metodo projects.locations.channels.events.get.

REST

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_NUMBER: il numero del tuo progetto Google Cloud, disponibile nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui si trova il tuo canale; utilizza una delle regioni supportate.
    Mostra località
    • 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
  • CHANNEL_ID: un identificatore del canale definito dall'utente.
  • EVENT_ID: un identificatore dell'evento definito dall'utente.

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID/events/EVENT_ID",
  "createTime": CREATE_TIME,
  "updateTime": UPDATE_TIME,
  "adBreak": {
    "duration": "10s"
  },
  "executeNow": true,
  "state": "SCHEDULED"
}

C#

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API C# per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


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

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Go per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

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

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Java per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


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

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Node.js per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

/**
 * 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

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API PHP per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

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

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Python per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


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

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Ruby per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

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

Elenca eventi del canale

Per elencare tutti gli eventi creati per un canale, utilizza il metodo projects.locations.channels.events.list.

REST

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_NUMBER: il numero del tuo progetto Google Cloud, disponibile nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui si trova il tuo canale; utilizza una delle regioni supportate.
    Mostra località
    • 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
  • CHANNEL_ID: un identificatore del canale definito dall'utente.

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{
    "events": [
      {
        "name": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID/events/my-event",
        "createTime": CREATE_TIME,
        "updateTime": UPDATE_TIME,
        "adBreak": {
          "duration": "10s"
        },
        "executeNow": true,
        "state": "SCHEDULED"
      },
      {
        "name": "projects/PROJECT_NUMBER/locations/LOCATION/channels/CHANNEL_ID/events/my-event2",
        "createTime": CREATE_TIME,
        "updateTime": UPDATE_TIME,
        "adBreak": {
          "duration": "10s"
        },
        "executeNow": true,
        "state": "SCHEDULED"
      }
  ]
}

C#

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API C# per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


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

public class ListChannelEventsSample
{
    public IList<Event> ListChannelEvents(
        string projectId, string regionId, string channelId)
    {
        // Create the client.
        LivestreamServiceClient client = LivestreamServiceClient.Create();

        ListEventsRequest request = new ListEventsRequest
        {
            ParentAsChannelName = ChannelName.FromProjectLocationChannel(projectId, regionId, channelId)
        };

        // Make the request.
        PagedEnumerable<ListEventsResponse, Event> response = client.ListEvents(request);

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

Go

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Go per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

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

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

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

	it := client.ListEvents(ctx, req)
	fmt.Fprintln(w, "Channel events:")

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

Java

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Java per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


import com.google.cloud.video.livestream.v1.ChannelName;
import com.google.cloud.video.livestream.v1.Event;
import com.google.cloud.video.livestream.v1.ListEventsRequest;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import java.io.IOException;

public class ListChannelEvents {

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

    listChannelEvents(projectId, location, channelId);
  }

  public static void listChannelEvents(String projectId, String location, String channelId)
      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 listEventsRequest =
          ListEventsRequest.newBuilder()
              .setParent(ChannelName.of(projectId, location, channelId).toString())
              .build();

      LivestreamServiceClient.ListEventsPagedResponse response =
          livestreamServiceClient.listEvents(listEventsRequest);
      System.out.println("Channel events:");

      for (Event event : response.iterateAll()) {
        System.out.println(event.getName());
      }
    }
  }
}

Node.js

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Node.js per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

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

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

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

async function listChannelEvents() {
  const iterable = await livestreamServiceClient.listEventsAsync({
    parent: livestreamServiceClient.channelPath(
      projectId,
      location,
      channelId
    ),
  });
  console.info('Channel events:');
  for await (const response of iterable) {
    console.log(response.name);
  }
}

listChannelEvents();

PHP

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API PHP per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

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

/**
 * Lists the channel events for a given channel.
 *
 * @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
 */
function list_channel_events(
    string $callingProjectId,
    string $location,
    string $channelId
): void {
    // Instantiate a client.
    $livestreamClient = new LivestreamServiceClient();
    $parent = $livestreamClient->channelName($callingProjectId, $location, $channelId);
    $request = (new ListEventsRequest())
        ->setParent($parent);

    $response = $livestreamClient->listEvents($request);
    // Print the channel list.
    $events = $response->iterateAllElements();
    print('Channel events:' . PHP_EOL);
    foreach ($events as $event) {
        printf('%s' . PHP_EOL, $event->getName());
    }
}

Python

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Python per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


import argparse

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

def list_channel_events(
    project_id: str, location: str, channel_id: str
) -> pagers.ListEventsPager:
    """Lists all events for a channel.
    Args:
        project_id: The GCP project ID.
        location: The location of the channel.
        channel_id: The user-defined channel ID."""

    client = LivestreamServiceClient()

    parent = f"projects/{project_id}/locations/{location}/channels/{channel_id}"
    page_result = client.list_events(parent=parent)
    print("Events:")

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

    return responses

Ruby

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Ruby per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

require "google/cloud/video/live_stream"

##
# List the channel events
#
# @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")
#
def list_channel_events project_id:, location:, channel_id:
  # Create a Live Stream client.
  client = Google::Cloud::Video::LiveStream.livestream_service

  # Build the resource name of the parent.
  parent = client.channel_path project: project_id, location: location, channel: channel_id

  # Get the list of channel events.
  response = client.list_events parent: parent

  puts "Channel events:"
  # Print out all channel events.
  response.each do |event|
    puts event.name
  end
end

Eliminare un evento del canale

Per eliminare un evento del canale, utilizza il metodo projects.locations.channels.events.delete.

L'API Live Stream elimina automaticamente un evento del canale sette giorni dopo l'esecuzione. Questa eliminazione include gli eventi non riusciti.

REST

Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:

  • PROJECT_NUMBER: il numero del tuo progetto Google Cloud, disponibile nel campo Numero di progetto della pagina Impostazioni IAM
  • LOCATION: la località in cui si trova il tuo canale; utilizza una delle regioni supportate.
    Mostra località
    • 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
  • CHANNEL_ID: un identificatore del canale definito dall'utente.
  • EVENT_ID: un identificatore dell'evento definito dall'utente.

Per inviare la richiesta, espandi una di queste opzioni:

Dovresti ricevere una risposta JSON simile alla seguente:

{}

C#

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API C# per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


using Google.Cloud.Video.LiveStream.V1;

public class DeleteChannelEventSample
{
    public void DeleteChannelEvent(
         string projectId, string locationId, string channelId, string eventId)
    {
        // Create the client.
        LivestreamServiceClient client = LivestreamServiceClient.Create();

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

        // Make the request.
        client.DeleteEvent(request);
    }
}

Go

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Go per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

import (
	"context"
	"fmt"
	"io"

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

// deleteChannelEvent deletes a previously-created channel event.
func deleteChannelEvent(w io.Writer, projectID, location, channelID, eventID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// channelID := "my-channel"
	// 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.DeleteEventRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/channels/%s/events/%s", projectID, location, channelID, eventID),
	}

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

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

Java

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Java per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


import com.google.cloud.video.livestream.v1.DeleteEventRequest;
import com.google.cloud.video.livestream.v1.EventName;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import java.io.IOException;

public class DeleteChannelEvent {

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

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

  public static void deleteChannelEvent(
      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()) {
      var deleteEventRequest =
          DeleteEventRequest.newBuilder()
              .setName(EventName.of(projectId, location, channelId, eventId).toString())
              .build();

      livestreamServiceClient.deleteEvent(deleteEventRequest);
      System.out.println("Deleted channel event");
    }
  }
}

Node.js

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Node.js per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

/**
 * 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 deleteChannelEvent() {
  // Construct request
  const request = {
    name: livestreamServiceClient.eventPath(
      projectId,
      location,
      channelId,
      eventId
    ),
  };

  // Run request
  await livestreamServiceClient.deleteEvent(request);
  console.log('Deleted channel event');
}

deleteChannelEvent();

PHP

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API PHP per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

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

/**
 * Deletes 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 to be deleted
 */
function delete_channel_event(
    string $callingProjectId,
    string $location,
    string $channelId,
    string $eventId
): void {
    // Instantiate a client.
    $livestreamClient = new LivestreamServiceClient();
    $formattedName = $livestreamClient->eventName($callingProjectId, $location, $channelId, $eventId);

    // Run the channel event deletion request.
    $request = (new DeleteEventRequest())
        ->setName($formattedName);
    $livestreamClient->deleteEvent($request);
    printf('Deleted channel event %s' . PHP_EOL, $eventId);
}

Python

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Python per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.


import argparse

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

def delete_channel_event(
    project_id: str, location: str, channel_id: str, event_id: str
) -> None:
    """Deletes a channel event.
    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.delete_event(name=name)
    print("Deleted channel event")

    return response

Ruby

Per scoprire come installare e utilizzare la libreria client per l'API Live Stream, consulta la pagina dedicata alle librerie client dell'API Live Stream. Per maggiori informazioni, consulta la documentazione di riferimento dell'API Ruby per l'API Live Stream.

Per eseguire l'autenticazione all'API Live Stream, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

require "google/cloud/video/live_stream"

##
# Delete 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 delete_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

  # Delete the channel event.
  client.delete_event name: name

  # Print a success message.
  puts "Deleted channel event"
end