Mengelola sesi live

Dengan Video Stitcher API, Anda membuat sesi live setiap kali memulai pemutaran livestream di mana iklan digabungkan secara dinamis selama jeda iklan. Respons akan berisi URL pemutaran dan konfigurasi sesi live.

Halaman ini menjelaskan cara membuat dan mengelola sesi live yang tidak diaktifkan oleh Google Ad Manager. Untuk informasi lebih lanjut mengenai jenis sesi live ini, lihat Mengelola sesi live yang diaktifkan oleh Google Ad Manager.

Sebelum memulai

Membuat sesi live

Untuk membuat sesi live, gunakan metode projects.locations.liveSessions.create.

Saat Anda membuat sesi live, kolom berikut bersifat opsional:

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • PROJECT_NUMBER: nomor project Google Cloud Anda yang berada di kolom Nomor project di halaman Setelan IAM
  • LOCATION: lokasi untuk membuat sesi; gunakan salah satu wilayah yang didukung
    Tampilkan lokasi
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • LIVE_CONFIG_ID: ID yang ditentukan pengguna untuk konfigurasi langsung

Untuk mengirim permintaan Anda, perluas salah satu opsi berikut:

Anda akan melihat respons JSON seperti berikut:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/liveSessions/SESSION_ID",
  "playUri": "PLAY_URI",
  "liveConfig": "projects/PROJECT_NUMBER/locations/LOCATION/liveConfigs/LIVE_CONFIG_ID",
}

C#

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan C# di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API C# API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


using Google.Cloud.Video.Stitcher.V1;

public class CreateLiveSessionSample
{
    public LiveSession CreateLiveSession(
        string projectId, string location, string liveConfigId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        CreateLiveSessionRequest request = new CreateLiveSessionRequest
        {
            Parent = $"projects/{projectId}/locations/{location}",
            LiveSession = new LiveSession
            {
                LiveConfig = LiveConfigName.FormatProjectLocationLiveConfig(projectId, location, liveConfigId)
            }
        };

        // Call the API.
        LiveSession session = client.CreateLiveSession(request);

        // Return the result.
        return session;
    }
}

Go

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Go di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Go API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import (
	"context"
	"fmt"
	"io"

	stitcher "cloud.google.com/go/video/stitcher/apiv1"
	"cloud.google.com/go/video/stitcher/apiv1/stitcherpb"
)

// createLiveSession creates a livestream session in which to insert ads.
// Live sessions are ephemeral resources that expire after a few minutes.
func createLiveSession(w io.Writer, projectID, liveConfigID string) error {
	// projectID := "my-project-id"
	// liveConfigID := "my-live-config"
	location := "us-central1"
	ctx := context.Background()
	client, err := stitcher.NewVideoStitcherClient(ctx)
	if err != nil {
		return fmt.Errorf("stitcher.NewVideoStitcherClient: %w", err)
	}
	defer client.Close()

	req := &stitcherpb.CreateLiveSessionRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location),
		LiveSession: &stitcherpb.LiveSession{
			LiveConfig: fmt.Sprintf("projects/%s/locations/%s/liveConfigs/%s", projectID, location, liveConfigID),
		},
	}
	// Creates the live session.
	response, err := client.CreateLiveSession(ctx, req)
	if err != nil {
		return fmt.Errorf("client.CreateLiveSession: %w", err)
	}

	fmt.Fprintf(w, "Live session: %v\n", response.GetName())
	fmt.Fprintf(w, "Play URI: %v", response.GetPlayUri())
	return nil
}

Java

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Java di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Java API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


import com.google.cloud.video.stitcher.v1.CreateLiveSessionRequest;
import com.google.cloud.video.stitcher.v1.LiveConfigName;
import com.google.cloud.video.stitcher.v1.LiveSession;
import com.google.cloud.video.stitcher.v1.LocationName;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import java.io.IOException;

public class CreateLiveSession {

  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 liveConfigId = "my-live-config-id";

    createLiveSession(projectId, location, liveConfigId);
  }

  public static void createLiveSession(String projectId, String location, String liveConfigId)
      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 (VideoStitcherServiceClient videoStitcherServiceClient =
        VideoStitcherServiceClient.create()) {
      CreateLiveSessionRequest createLiveSessionRequest =
          CreateLiveSessionRequest.newBuilder()
              .setParent(LocationName.of(projectId, location).toString())
              .setLiveSession(
                  LiveSession.newBuilder()
                      .setLiveConfig(LiveConfigName.format(projectId, location, liveConfigId)))
              .build();

      LiveSession response = videoStitcherServiceClient.createLiveSession(createLiveSessionRequest);
      System.out.println("Created live session: " + response.getName());
      System.out.println("Play URI: " + response.getPlayUri());
    }
  }
}

Node.js

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Node.js di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Node.js API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

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

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
  require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function createLiveSession() {
  // Construct request
  const request = {
    parent: stitcherClient.locationPath(projectId, location),
    liveSession: {
      liveConfig: stitcherClient.liveConfigPath(
        projectId,
        location,
        liveConfigId
      ),
    },
  };

  const [session] = await stitcherClient.createLiveSession(request);
  console.log(`Live session: ${session.name}`);
  console.log(`Play URI: ${session.playUri}`);
}

createLiveSession();

PHP

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan PHP di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API PHP API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
use Google\Cloud\Video\Stitcher\V1\CreateLiveSessionRequest;
use Google\Cloud\Video\Stitcher\V1\LiveSession;

/**
 * Creates a live session. Live sessions are ephemeral resources that expire
 * after a few minutes.
 *
 * @param string $callingProjectId     The project ID to run the API call under
 * @param string $location             The location of the session
 * @param string $liveConfigId         The live config ID to use to create the
 *                                     live session
 */
function create_live_session(
    string $callingProjectId,
    string $location,
    string $liveConfigId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $parent = $stitcherClient->locationName($callingProjectId, $location);
    $liveConfig = $stitcherClient->liveConfigName($callingProjectId, $location, $liveConfigId);
    $liveSession = new LiveSession();
    $liveSession->setLiveConfig($liveConfig);

    // Run live session creation request
    $request = (new CreateLiveSessionRequest())
        ->setParent($parent)
        ->setLiveSession($liveSession);
    $response = $stitcherClient->createLiveSession($request);

    // Print results
    printf('Live session: %s' . PHP_EOL, $response->getName());
}

Python

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Python di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Python API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


import argparse

from google.cloud.video import stitcher_v1
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
    VideoStitcherServiceClient,
)


def create_live_session(
    project_id: str, location: str, live_config_id: str
) -> stitcher_v1.types.LiveSession:
    """Creates a live session. Live sessions are ephemeral resources that expire
    after a few minutes.
    Args:
        project_id: The GCP project ID.
        location: The location in which to create the session.
        live_config_id: The user-defined live config ID.

    Returns:
        The live session resource.
    """

    client = VideoStitcherServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    live_config = (
        f"projects/{project_id}/locations/{location}/liveConfigs/{live_config_id}"
    )

    live_session = stitcher_v1.types.LiveSession(live_config=live_config)

    response = client.create_live_session(parent=parent, live_session=live_session)
    print(f"Live session: {response.name}")
    return response

Ruby

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Ruby di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Ruby API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

require "google/cloud/video/stitcher"

##
# Create a live stream session. Live sessions are ephemeral resources
# that expire after a few minutes.
#
# @param project_id [String] Your Google Cloud project (e.g. "my-project")
# @param location [String] The location (e.g. "us-central1")
# @param live_config_id [String] Your live config name (e.g. "my-live-config")
#
def create_live_session project_id:, location:, live_config_id:
  # Create a Video Stitcher client.
  client = Google::Cloud::Video::Stitcher.video_stitcher_service

  # Build the resource name of the parent.
  parent = client.location_path project: project_id, location: location

  # Build the resource name of the live config.
  live_config_name = client.live_config_path project: project_id,
                                             location: location,
                                             live_config: live_config_id

  # Set the session fields.
  new_live_session = {
    live_config: live_config_name
  }

  response = client.create_live_session parent: parent,
                                        live_session: new_live_session

  # Print the live session name.
  puts "Live session: #{response.name}"
end

Responsnya adalah objek sesi live. playUri adalah URL yang digunakan perangkat klien untuk memutar streaming yang digabungkan dengan iklan untuk sesi live ini.

Video Stitcher API menghasilkan ID sesi yang unik untuk setiap permintaan. Sesi akan berakhir jika playUri tidak diminta dalam 5 menit terakhir.

Iklan harus dienkode sebelum dapat digabungkan ke sesi live. Saat Anda membuat sesi untuk video yang digabungkan iklan, Video Stitcher API akan menentukan apakah iklan telah dienkode dari sesi sebelumnya. API hanya mencari iklan berenkode yang dibuat oleh sesi yang terkait dengan project Google Cloud Anda. Untuk informasi selengkapnya tentang proses ini, lihat Ringkasan.

Jika membuat sesi atas nama perangkat pelanggan, Anda dapat menetapkan parameter berikut menggunakan header HTTP:

Parameter Header HTTP
CLIENT_IP x-forwarded-for
REFERRER_URL referer
USER_AGENT user-agent

Anda dapat menambahkan header berikut ke permintaan curl sebelumnya:

-H "x-forwarded-for: CLIENT_IP" \
-H "referer: REFERRER_URL" \
-H "user-agent: USER_AGENT" \

Jika header x-forwarded-for tidak diberikan, Video Stitcher API akan menggunakan alamat IP klien dalam permintaan metadata iklan. Perlu diketahui bahwa alamat IP klien mungkin tidak sama dengan IP perangkat pelanggan Anda jika sesi dibuat atas nama perangkat pelanggan Anda.

Makro tag iklan

Tag iklan dapat berisi makro, yang dapat menghasilkan tag iklan berbeda untuk setiap sesi. Makro ditunjukkan dengan tanda kurung siku dalam tag iklan, seperti yang ditunjukkan oleh contoh berikut:

AD_TAG_URI&macro=[my-key]

adTagUri ditentukan dalam konfigurasi langsung.

Untuk mengganti nilai dalam makro tag iklan, berikan pemetaan di kolom adTagMacros. Misalnya, jika ingin mengganti makro [my-key] dengan string my-value, Anda harus menyediakan hal berikut:

{
  ...
  "adTagMacros": {
    "my-key": "my-value"
  },
  ...
}

Saat Video Stitcher API meminta metadata iklan, Video Stitcher API akan menggunakan tag iklan berikut:

AD_TAG_URI&macro=my-value

Mendapatkan sesi

Untuk mendapatkan sesi live, gunakan metode projects.locations.liveSessions.get.

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • PROJECT_NUMBER: nomor project Google Cloud Anda yang berada di kolom Nomor project di halaman Setelan IAM
  • LOCATION: lokasi untuk membuat sesi; gunakan salah satu wilayah yang didukung
    Tampilkan lokasi
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • SESSION_ID: ID untuk sesi live

Untuk mengirim permintaan Anda, perluas salah satu opsi berikut:

Anda akan melihat respons JSON seperti berikut:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/liveSessions/SESSION_ID",
  "playUri": "ad-stitched-live-stream-uri",
  "liveConfig": "projects/PROJECT_NUMBER/locations/LOCATION/liveConfigs/LIVE_CONFIG_ID",
}

C#

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan C# di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API C# API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


using Google.Cloud.Video.Stitcher.V1;

public class GetLiveSessionSample
{
    public LiveSession GetLiveSession(
        string projectId, string location, string sessionId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        GetLiveSessionRequest request = new GetLiveSessionRequest
        {
            LiveSessionName = LiveSessionName.FromProjectLocationLiveSession(projectId, location, sessionId)
        };

        // Call the API.
        LiveSession session = client.GetLiveSession(request);

        // Return the result.
        return session;
    }
}

Go

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Go di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Go API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import (
	"context"
	"fmt"
	"io"

	stitcher "cloud.google.com/go/video/stitcher/apiv1"
	"cloud.google.com/go/video/stitcher/apiv1/stitcherpb"
)

// getLiveSession gets a livestream session by ID.
func getLiveSession(w io.Writer, projectID, sessionID string) error {
	// projectID := "my-project-id"
	// sessionID := "123-456-789"
	location := "us-central1"
	ctx := context.Background()
	client, err := stitcher.NewVideoStitcherClient(ctx)
	if err != nil {
		return fmt.Errorf("stitcher.NewVideoStitcherClient: %w", err)
	}
	defer client.Close()

	req := &stitcherpb.GetLiveSessionRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/liveSessions/%s", projectID, location, sessionID),
	}
	// Gets the session.
	response, err := client.GetLiveSession(ctx, req)
	if err != nil {
		return fmt.Errorf("client.GetLiveSession: %w", err)
	}

	fmt.Fprintf(w, "Live session: %+v", response)
	return nil
}

Java

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Java di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Java API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


import com.google.cloud.video.stitcher.v1.GetLiveSessionRequest;
import com.google.cloud.video.stitcher.v1.LiveSession;
import com.google.cloud.video.stitcher.v1.LiveSessionName;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import java.io.IOException;

public class GetLiveSession {

  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 sessionId = "my-session-id";

    getLiveSession(projectId, location, sessionId);
  }

  public static void getLiveSession(String projectId, String location, String sessionId)
      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 (VideoStitcherServiceClient videoStitcherServiceClient =
        VideoStitcherServiceClient.create()) {
      GetLiveSessionRequest getLiveSessionRequest =
          GetLiveSessionRequest.newBuilder()
              .setName(LiveSessionName.of(projectId, location, sessionId).toString())
              .build();

      LiveSession response = videoStitcherServiceClient.getLiveSession(getLiveSessionRequest);
      System.out.println("Live session: " + response.getName());
    }
  }
}

Node.js

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Node.js di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Node.js API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

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

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
  require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function getLiveSession() {
  // Construct request
  const request = {
    name: stitcherClient.liveSessionPath(projectId, location, sessionId),
  };
  const [session] = await stitcherClient.getLiveSession(request);
  console.log(`Live session: ${session.name}`);
}

getLiveSession();

PHP

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan PHP di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API PHP API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
use Google\Cloud\Video\Stitcher\V1\GetLiveSessionRequest;

/**
 * Gets a live session.
 *
 * @param string $callingProjectId     The project ID to run the API call under
 * @param string $location             The location of the session
 * @param string $sessionId            The ID of the session
 */
function get_live_session(
    string $callingProjectId,
    string $location,
    string $sessionId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->liveSessionName($callingProjectId, $location, $sessionId);
    $request = (new GetLiveSessionRequest())
        ->setName($formattedName);
    $session = $stitcherClient->getLiveSession($request);

    // Print results
    printf('Live session: %s' . PHP_EOL, $session->getName());
}

Python

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Python di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Python API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


import argparse

from google.cloud.video import stitcher_v1
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
    VideoStitcherServiceClient,
)


def get_live_session(
    project_id: str, location: str, session_id: str
) -> stitcher_v1.types.LiveSession:
    """Gets a live session. Live sessions are ephemeral resources that expire
    after a few minutes.
    Args:
        project_id: The GCP project ID.
        location: The location of the session.
        session_id: The ID of the live session.

    Returns:
        The live session resource.
    """

    client = VideoStitcherServiceClient()

    name = client.live_session_path(project_id, location, session_id)
    response = client.get_live_session(name=name)
    print(f"Live session: {response.name}")
    return response

Ruby

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Ruby di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Ruby API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

require "google/cloud/video/stitcher"

##
# Get a live session. Live sessions are ephemeral resources
# that expire after a few minutes.
#
# @param project_id [String] Your Google Cloud project (e.g. "my-project")
# @param location [String] The location (e.g. "us-central1")
# @param session_id [String] The live session ID (e.g. "my-live-session-id")
#
def get_live_session project_id:, location:, session_id:
  # Create a Video Stitcher client.
  client = Google::Cloud::Video::Stitcher.video_stitcher_service

  # Build the resource name of the live session.
  name = client.live_session_path project: project_id, location: location,
                                  live_session: session_id

  # Get the live session.
  session = client.get_live_session name: name

  # Print the live session name.
  puts "Live session: #{session.name}"
end

Contoh playlist yang digabungkan dengan iklan

Berikut adalah contoh playlist live sumber sebelum penggabungan iklan:

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:5
#EXTINF:10.010
segment_00005.ts
#EXTINF:10.010
segment_00006.ts
#EXT-X-DATERANGE:ID="2415919105",START-DATE="2021-06-22T08:32:00Z",DURATION=60,SCTE35-OUT=0xF...
#EXTINF:10.010
segment_00007.ts
#EXTINF:10.010
segment_00008.ts
#EXT-X-DATERANGE:ID="2415919105",START-DATE="2021-06-22T08:39:20Z",SCTE35-IN=0xF...
#EXTINF:10.010
segment_00009.ts

Berikut adalah contoh playlist live sumber setelah penggabungan iklan:

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:5
#EXTINF:10.010
segment_00005.ts
#EXTINF:10.010
segment_00006.ts
#EXT-X-DISCONTINUITY
#EXTINF:6.000
https://ads.us-west1.cdn.videostitcher.goog/ad-1/seg-1.ts
#EXTINF:5.000
https://ads.us-west1.cdn.videostitcher.goog/ad-1/seg-2.ts
#EXT-X-DISCONTINUITY
#EXTINF:6.000
https://ads.us-west1.cdn.videostitcher.goog/ad-2/seg-1.ts
#EXTINF:5.000
https://ads.us-west1.cdn.videostitcher.goog/ad-2/seg-2.ts
#EXT-X-DISCONTINUITY
#EXTINF:10.010
segment_00009.ts

Menangani pelacakan iklan sisi klien

Saat pelacakan iklan klien diaktifkan, pemutar bertanggung jawab untuk memicu peristiwa pelacakan iklan. Metadata iklan yang disediakan oleh Video Stitcher API mencakup informasi pelacakan iklan dan iklan pengiring. Video Stitcher API akan mengurai informasi ini dari respons tag iklan.

Mendapatkan URI metadata iklan HLS dari manifes

Dalam manifes rendisi HLS, AdMetadataURI dienkode dalam atribut X-VAST-META dari tag #EXT-X-DATERANGE. Tag #EXT-X-DATERANGE dapat ditemukan sebelum segmen pertama yang digabungkan dari setiap iklan.

Berikut adalah contoh tag metadata dengan waktu HLS:

#EXT-X-DATERANGE:ID="id123",START-DATE=2014-03-05T11:15:00Z,DURATION=15,X-VAST-META="eyJBZE1ldGFkYXRhVXJpIjogImh0dHBzOi8vZXhhbXBsZS5jb20vdjFhbHBoYS9wcm9qZWN0cy8xMjMvbG9jYXRpb25zL3VzLWNlbnRyYWwxL2xpdmVTZXNzaW9ucy9hYmMzMjEvYWRNZXRhZGF0YS9pZDEyMyJ9"

Nilai atribut X-VAST-META adalah string JSON berenkode base64. Setelah mendekode, Anda dapat mengekstrak AdMetadataURI dari JSON.

Contoh berikut menunjukkan X-VAST-META yang didekode:

{
  "AdMetadataUri": "https://example.com/v1/projects/123/locations/us-central1/liveSessions/abc321/adMetadata/id123"
}

Mendapatkan URI metadata iklan DASH dari manifes

Dalam manifes DASH, setiap periode iklan yang digabungkan berisi satu iklan VAST, dan URI metadata iklannya dapat diekstrak dari dalam tag EventStream. AdMetadataURI dienkode dalam atribut messageData dari elemen Event. Event adalah elemen di dalam tag EventStream dengan schemeIdUri dari urn:videostitcher:admetadata:202008.

Berikut adalah contoh tag aliran peristiwa DASH:

<EventStream schemeIdUri="urn:videostitcher:admetadata:202008" timescale="1000">
  <Event duration="5000" messageData="eyJBZE1ldGFkYXRhVXJpIjogImh0dHBzOi8vZXhhbXBsZS5jb20vdjFhbHBoYS9wcm9qZWN0cy8xMjMvbG9jYXRpb25zL3VzLWNlbnRyYWwxL2xpdmVTZXNzaW9ucy9hYmMzMjEvYWRNZXRhZGF0YS9pZDEyMyJ9"></Event>
</EventStream>

Gunakan base64 untuk mendekode messageData ke JSON.

Contoh berikut menunjukkan messageData yang didekode:

{
  "AdMetadataUri": "https://example.com/v1/projects/123/locations/us-central1/liveSessions/abc321/adMetadata/id123"
}

Mengambil dan memproses peristiwa pelacakan iklan

Setelah mendapatkan AdMetadataURI, Anda dapat mengambil metadata iklan.

Contoh berikut menampilkan metadata iklan:

{
  "activityEvents": [
    {
      "type": "PAUSE",
      "uri": "https://example.com/pause"
    }
  ],
  "progressiveEvents": [
    {
      "timeOffset": "0s",
      "events": [
        {
          "type": "IMPRESSION",
          "uri": "https://example.com/impression"
        },
        {
          "type": "START",
          "uri": "https://example.com/start"
        }
      ]
    },
    {
      "timeOffset": "2.500s",
      "events": [
        {
          "type": "FIRST_QUARTILE",
          "uri": "https://example.com/firstquartile"
        }
      ]
    }
  ],
  "adDuration": "10s"
}

Dalam contoh sebelumnya, klien harus melakukan hal berikut:

  • Minta https://example.com/start di awal video iklan
  • Minta https://example.com/impression di awal video iklan
  • Minta https://example.com/pause setiap kali penonton menjeda video iklan
  • Minta https://example.com/firstQuartile memasukkan 2,5 detik ke video iklan

Periksa sesi live

Bagian ini menjelaskan cara memeriksa sesi live dan detail tag iklan untuk sesi live tertentu. Untuk mengetahui detail lebih lanjut, lihat dokumentasi REST.

Video Stitcher API mengirimkan permintaan ke penyedia iklan yang ditentukan dalam tag iklan dalam isi permintaan sesi live. Metadata permintaan dan respons untuk permintaan ini disimpan selama 14 hari dan dapat dilihat dengan memeriksa sesi live.

Video Stitcher API menyusun detail tag iklan menggunakan hal berikut:

  • URL tag iklan yang diminta dalam jeda iklan tertentu (atau tag iklan default, jika tidak ada yang ditentukan)
  • Makro tag iklan yang dikonfigurasi dari permintaan sesi langsung
  • Metadata pengguna tambahan

Informasi ini, beserta isi dan metadata respons, memberikan insight tentang perilaku Video Stitcher API.

Menampilkan detail tag iklan

Untuk mencantumkan detail tag iklan untuk sesi live, gunakan metode projects.locations.liveSessions.liveAdTagDetails.list.

Pertimbangkan respons berikut untuk sesi live yang dibuat sebelumnya (beberapa kolom dihilangkan):

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/liveSessions/SESSION_ID",
  ...
}

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • PROJECT_NUMBER: nomor project Google Cloud Anda yang berada di kolom Nomor project di halaman Setelan IAM
  • LOCATION: lokasi sesi Anda; gunakan salah satu wilayah yang didukung
    Tampilkan lokasi
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • SESSION_ID: ID untuk sesi live

Untuk mengirim permintaan Anda, perluas salah satu opsi berikut:

Anda akan melihat respons JSON seperti berikut:

{
  "liveAdTagDetails" : [
    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/liveSessions/SESSION_ID/liveAdTagDetails/LIVE_AD_TAG_DETAILS_ID",
      "adRequests": [
        {
          "uri": "REQUEST_URL",
          "requestMetadata": "AD_TAG_REQUEST_METADATA",
          "responseMetadata": "AD_TAG_RESPONSE_METADATA"
        }
      ]
    }
  ]
}

Salin LIVE_AD_TAG_DETAILS_ID yang ditampilkan. Anda memerlukannya untuk mendapatkan detail untuk satu tag iklan.

C#

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan C# di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API C# API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


using Google.Api.Gax;
using Google.Cloud.Video.Stitcher.V1;

public class ListLiveAdTagDetailsSample
{
    public PagedEnumerable<ListLiveAdTagDetailsResponse, LiveAdTagDetail> ListLiveAdTagDetails(
        string projectId, string regionId, string sessionId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        ListLiveAdTagDetailsRequest request = new ListLiveAdTagDetailsRequest
        {
            ParentAsLiveSessionName = LiveSessionName.FromProjectLocationLiveSession(projectId, regionId, sessionId)
        };

        // Make the request.
        PagedEnumerable<ListLiveAdTagDetailsResponse, LiveAdTagDetail> response = client.ListLiveAdTagDetails(request);

        // Return the result.
        return response;
    }
}

Go

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Go di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Go API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import (
	"context"
	"fmt"
	"io"

	stitcher "cloud.google.com/go/video/stitcher/apiv1"
	stitcherstreampb "cloud.google.com/go/video/stitcher/apiv1/stitcherpb"
	"google.golang.org/api/iterator"
)

// listLiveAdTagDetails lists the ad tag details for the specified live session.
func listLiveAdTagDetails(w io.Writer, projectID, sessionID string) error {
	// projectID := "my-project-id"
	// sessionID := "my-session-id"
	location := "us-central1"
	ctx := context.Background()
	client, err := stitcher.NewVideoStitcherClient(ctx)
	if err != nil {
		return fmt.Errorf("stitcher.NewVideoStitcherClient: %w", err)
	}
	defer client.Close()

	req := &stitcherstreampb.ListLiveAdTagDetailsRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s/liveSessions/%s", projectID, location, sessionID),
	}

	it := client.ListLiveAdTagDetails(ctx, req)
	fmt.Fprintln(w, "Live ad tag details:")
	for {
		response, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("it.Next(): %w", err)
		}
		fmt.Fprintln(w, response.GetName())
	}
	return nil
}

Java

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Java di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Java API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


import com.google.cloud.video.stitcher.v1.ListLiveAdTagDetailsRequest;
import com.google.cloud.video.stitcher.v1.LiveAdTagDetail;
import com.google.cloud.video.stitcher.v1.LiveSessionName;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import java.io.IOException;

public class ListLiveAdTagDetails {

  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 sessionId = "my-session-id";

    listLiveAdTagDetails(projectId, location, sessionId);
  }

  public static void listLiveAdTagDetails(String projectId, String location, String sessionId)
      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 (VideoStitcherServiceClient videoStitcherServiceClient =
        VideoStitcherServiceClient.create()) {
      ListLiveAdTagDetailsRequest listLiveAdTagDetailsRequest =
          ListLiveAdTagDetailsRequest.newBuilder()
              .setParent(LiveSessionName.of(projectId, location, sessionId).toString())
              .build();

      VideoStitcherServiceClient.ListLiveAdTagDetailsPagedResponse response =
          videoStitcherServiceClient.listLiveAdTagDetails(listLiveAdTagDetailsRequest);
      System.out.println("Live ad tag details:");

      for (LiveAdTagDetail adTagDetail : response.iterateAll()) {
        System.out.println(adTagDetail.toString());
      }
    }
  }
}

Node.js

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Node.js di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Node.js API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

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

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
  require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function listLiveAdTagDetails() {
  // Construct request
  const request = {
    parent: stitcherClient.liveSessionPath(projectId, location, sessionId),
  };
  const iterable = await stitcherClient.listLiveAdTagDetailsAsync(request);
  console.log('Live ad tag details:');
  for await (const response of iterable) {
    console.log(response.name);
  }
}

listLiveAdTagDetails();

PHP

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan PHP di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API PHP API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
use Google\Cloud\Video\Stitcher\V1\ListLiveAdTagDetailsRequest;

/**
 * Lists the ad tag details for the specified live session.
 *
 * @param string $callingProjectId     The project ID to run the API call under
 * @param string $location             The location of the session
 * @param string $sessionId            The ID of the session
 */
function list_live_ad_tag_details(
    string $callingProjectId,
    string $location,
    string $sessionId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->liveSessionName($callingProjectId, $location, $sessionId);
    $request = (new ListLiveAdTagDetailsRequest())
        ->setParent($formattedName);
    $response = $stitcherClient->listLiveAdTagDetails($request);

    // Print the ad tag details list.
    $adTagDetails = $response->iterateAllElements();
    print('Live ad tag details:' . PHP_EOL);
    foreach ($adTagDetails as $adTagDetail) {
        printf('%s' . PHP_EOL, $adTagDetail->getName());
    }
}

Python

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Python di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Python API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


import argparse

from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
    pagers,
    VideoStitcherServiceClient,
)


def list_live_ad_tag_details(
    project_id: str, location: str, session_id: str
) -> pagers.ListLiveAdTagDetailsPager:
    """Lists the ad tag details for the specified live session.
    Args:
        project_id: The GCP project ID.
        location: The location of the session.
        session_id: The ID of the live session.

    Returns:
        An iterable object containing live ad tag details resources.
    """

    client = VideoStitcherServiceClient()

    parent = client.live_session_path(project_id, location, session_id)
    page_result = client.list_live_ad_tag_details(parent=parent)
    print("Live ad tag details:")
    for response in page_result:
        print(response)

    return page_result

Ruby

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Ruby di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Ruby API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

require "google/cloud/video/stitcher"

##
# List the ad tag details for a live session
#
# @param project_id [String] Your Google Cloud project (e.g. "my-project")
# @param location [String] The location (e.g. "us-central1")
# @param session_id [String] The live session ID (e.g. "my-live-session-id")
#
def list_live_ad_tag_details project_id:, location:, session_id:
  # Create a Video Stitcher client.
  client = Google::Cloud::Video::Stitcher.video_stitcher_service

  # Build the resource name of the parent.
  parent = client.live_session_path project: project_id, location: location,
                                    live_session: session_id

  # List all ad tag details for the live session.
  response = client.list_live_ad_tag_details parent: parent

  puts "Live ad tag details:"
  # Print out all live ad tag details.
  response.each do |live_ad_tag_detail|
    puts live_ad_tag_detail.name
  end
end

Dapatkan detail tag iklan

Untuk mendapatkan detail untuk satu detail tag iklan dalam sesi live, gunakan metode projects.locations.liveSessions.liveAdTagDetails.get.

Contoh berikut menunjukkan cara melihat detail tag iklan tunggal untuk sesi live menggunakan nama detail tag iklan yang ditampilkan dari permintaan sebelumnya:

REST

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • PROJECT_NUMBER: nomor project Google Cloud Anda yang berada di kolom Nomor project di halaman Setelan IAM
  • LOCATION: lokasi sesi Anda; gunakan salah satu wilayah yang didukung
    Tampilkan lokasi
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • SESSION_ID: ID untuk sesi live
  • LIVE_AD_TAG_DETAILS_ID: ID untuk detail tag iklan aktif

Untuk mengirim permintaan Anda, perluas salah satu opsi berikut:

Anda akan melihat respons JSON seperti berikut:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/liveSessions/SESSION_ID/liveAdTagDetails/LIVE_AD_TAG_DETAILS_ID",
  "adRequests": [
    {
      "uri": "REQUEST_URL",
      "requestMetadata": "AD_TAG_REQUEST_METADATA",
      "responseMetadata": "AD_TAG_RESPONSE_METADATA"
    }
  ]
}

C#

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan C# di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API C# API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


using Google.Cloud.Video.Stitcher.V1;

public class GetLiveAdTagDetailSample
{
    public LiveAdTagDetail GetLiveAdTagDetail(
        string projectId, string location, string sessionId, string adTagDetailId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        GetLiveAdTagDetailRequest request = new GetLiveAdTagDetailRequest
        {
            LiveAdTagDetailName = LiveAdTagDetailName.FromProjectLocationLiveSessionLiveAdTagDetail(projectId, location, sessionId, adTagDetailId)
        };

        // Call the API.
        LiveAdTagDetail liveAdTagDetail = client.GetLiveAdTagDetail(request);

        // Return the result.
        return liveAdTagDetail;
    }
}

Go

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Go di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Go API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import (
	"context"
	"encoding/json"
	"fmt"
	"io"

	stitcher "cloud.google.com/go/video/stitcher/apiv1"
	stitcherstreampb "cloud.google.com/go/video/stitcher/apiv1/stitcherpb"
)

// getLiveAdTagDetail gets the specified ad tag detail for a live session.
func getLiveAdTagDetail(w io.Writer, projectID, sessionID, adTagDetailID string) error {
	// projectID := "my-project-id"
	// sessionID := "my-session-id"
	// adTagDetailID := "my-ad-tag-detail-id"
	location := "us-central1"
	ctx := context.Background()
	client, err := stitcher.NewVideoStitcherClient(ctx)
	if err != nil {
		return fmt.Errorf("stitcher.NewVideoStitcherClient: %w", err)
	}
	defer client.Close()

	req := &stitcherstreampb.GetLiveAdTagDetailRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/liveSessions/%s/liveAdTagDetails/%s", projectID, location, sessionID, adTagDetailID),
	}
	// Gets the ad tag detail.
	response, err := client.GetLiveAdTagDetail(ctx, req)
	if err != nil {
		return fmt.Errorf("client.GetLiveAdTagDetail: %w", err)
	}
	b, err := json.MarshalIndent(response, "", " ")
	if err != nil {
		return fmt.Errorf("json.MarshalIndent: %w", err)
	}
	fmt.Fprintf(w, "Live ad tag detail:\n%v", string(b))
	return nil
}

Java

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Java di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Java API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


import com.google.cloud.video.stitcher.v1.GetLiveAdTagDetailRequest;
import com.google.cloud.video.stitcher.v1.LiveAdTagDetail;
import com.google.cloud.video.stitcher.v1.LiveAdTagDetailName;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import java.io.IOException;

public class GetLiveAdTagDetail {

  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 sessionId = "my-session-id";
    String adTagDetailId = "my-ad-tag-detail-id";

    getLiveAdTagDetail(projectId, location, sessionId, adTagDetailId);
  }

  public static void getLiveAdTagDetail(
      String projectId, String location, String sessionId, String adTagDetailId)
      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 (VideoStitcherServiceClient videoStitcherServiceClient =
        VideoStitcherServiceClient.create()) {
      GetLiveAdTagDetailRequest getLiveAdTagDetailRequest =
          GetLiveAdTagDetailRequest.newBuilder()
              .setName(
                  LiveAdTagDetailName.of(projectId, location, sessionId, adTagDetailId).toString())
              .build();

      LiveAdTagDetail response =
          videoStitcherServiceClient.getLiveAdTagDetail(getLiveAdTagDetailRequest);
      System.out.println("Live ad tag detail: " + response.getName());
    }
  }
}

Node.js

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Node.js di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Node.js API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// projectId = 'my-project-id';
// location = 'us-central1';
// sessionId = 'my-session-id';
// adTagDetailId = 'my-ad-tag-detail-id';

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
  require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function getLiveAdTagDetail() {
  // Construct request
  const request = {
    name: stitcherClient.liveAdTagDetailPath(
      projectId,
      location,
      sessionId,
      adTagDetailId
    ),
  };
  const [adTagDetail] = await stitcherClient.getLiveAdTagDetail(request);
  console.log(`Live ad tag detail: ${adTagDetail.name}`);
}

getLiveAdTagDetail();

PHP

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan PHP di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API PHP API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
use Google\Cloud\Video\Stitcher\V1\GetLiveAdTagDetailRequest;

/**
 * Gets the specified ad tag detail for the live session.
 *
 * @param string $callingProjectId     The project ID to run the API call under
 * @param string $location             The location of the session
 * @param string $sessionId            The ID of the session
 * @param string $adTagDetailId        The ID of the ad tag detail
 */
function get_live_ad_tag_detail(
    string $callingProjectId,
    string $location,
    string $sessionId,
    string $adTagDetailId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->liveAdTagDetailName($callingProjectId, $location, $sessionId, $adTagDetailId);
    $request = (new GetLiveAdTagDetailRequest())
        ->setName($formattedName);
    $adTagDetail = $stitcherClient->getLiveAdTagDetail($request);

    // Print results
    printf('Live ad tag detail: %s' . PHP_EOL, $adTagDetail->getName());
}

Python

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Python di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Python API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


import argparse

from google.cloud.video import stitcher_v1
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
    VideoStitcherServiceClient,
)


def get_live_ad_tag_detail(
    project_id: str, location: str, session_id: str, ad_tag_detail_id: str
) -> stitcher_v1.types.LiveAdTagDetail:
    """Gets the specified ad tag detail for a live session.
    Args:
        project_id: The GCP project ID.
        location: The location of the session.
        session_id: The ID of the live session.
        ad_tag_detail_id: The ID of the ad tag details.

    Returns:
        The live ad tag detail resource.
    """

    client = VideoStitcherServiceClient()

    name = client.live_ad_tag_detail_path(
        project_id, location, session_id, ad_tag_detail_id
    )
    response = client.get_live_ad_tag_detail(name=name)
    print(f"Live ad tag detail: {response.name}")
    return response

Ruby

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Ruby di panduan memulai Video Stitcher API menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Video Stitcher API Ruby API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

require "google/cloud/video/stitcher"

##
# Get the specified ad tag detail for a live session
#
# @param project_id [String] Your Google Cloud project (e.g. "my-project")
# @param location [String] The location (e.g. "us-central1")
# @param session_id [String] The live session ID (e.g. "my-live-session-id")
# @param ad_tag_detail_id [String] The ad tag detail ID (e.g. "my-ad-tag-id")
#
def get_live_ad_tag_detail project_id:, location:, session_id:,
                           ad_tag_detail_id:
  # Create a Video Stitcher client.
  client = Google::Cloud::Video::Stitcher.video_stitcher_service

  # Build the resource name of the live ad tag detail.
  name = client.live_ad_tag_detail_path project: project_id, location: location,
                                        live_session: session_id,
                                        live_ad_tag_detail: ad_tag_detail_id

  # Get the live ad tag detail.
  ad_tag_detail = client.get_live_ad_tag_detail name: name

  # Print the live ad tag detail name.
  puts "Live ad tag detail: #{ad_tag_detail.name}"
end