Mendapatkan sesi VOD

Dapatkan detail untuk referensi sesi VOD Video Stitcher.

Jelajahi lebih lanjut

Untuk dokumentasi mendetail yang menyertakan contoh kode ini, lihat artikel berikut:

Contoh kode

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 API C# Video Stitcher API.

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


using Google.Cloud.Video.Stitcher.V1;

public class GetVodSessionSample
{
    public VodSession GetVodSession(
        string projectId, string location, string sessionId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        GetVodSessionRequest request = new GetVodSessionRequest
        {
            VodSessionName = VodSessionName.FromProjectLocationVodSession(projectId, location, sessionId)
        };

        // Call the API.
        VodSession session = client.GetVodSession(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 API Go Video Stitcher API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca 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"
)

// getVodSession gets a VOD session by ID.
func getVodSession(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 := &stitcherstreampb.GetVodSessionRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/vodSessions/%s", projectID, location, sessionID),
	}
	// Gets the session.
	response, err := client.GetVodSession(ctx, req)
	if err != nil {
		return fmt.Errorf("client.GetVodSession: %w", err)
	}
	b, err := json.MarshalIndent(response, "", " ")
	if err != nil {
		return fmt.Errorf("json.MarshalIndent: %w", err)
	}

	fmt.Fprintf(w, "VOD session:\n%s", 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 API Java Video Stitcher API.

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


import com.google.cloud.video.stitcher.v1.GetVodSessionRequest;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import com.google.cloud.video.stitcher.v1.VodSession;
import com.google.cloud.video.stitcher.v1.VodSessionName;
import java.io.IOException;

public class GetVodSession {

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

    getVodSession(projectId, location, sessionId);
  }

  public static void getVodSession(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()) {
      GetVodSessionRequest getVodSessionRequest =
          GetVodSessionRequest.newBuilder()
              .setName(VodSessionName.of(projectId, location, sessionId).toString())
              .build();

      VodSession response = videoStitcherServiceClient.getVodSession(getVodSessionRequest);
      System.out.println("VOD 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 API Node.js Video Stitcher API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca 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 getVodSession() {
  // Construct request
  const request = {
    name: stitcherClient.vodSessionPath(projectId, location, sessionId),
  };
  const [session] = await stitcherClient.getVodSession(request);
  console.log(`VOD session: ${session.name}`);
}

getVodSession();

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 API PHP Video Stitcher API.

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

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

/**
 * Gets a VOD 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_vod_session(
    string $callingProjectId,
    string $location,
    string $sessionId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->vodSessionName($callingProjectId, $location, $sessionId);
    $request = (new GetVodSessionRequest())
        ->setName($formattedName);
    $session = $stitcherClient->getVodSession($request);

    // Print results
    printf('VOD 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 API Python Video Stitcher API.

Untuk mengautentikasi ke Video Stitcher API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca 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_vod_session(
    project_id: str, location: str, session_id: str
) -> stitcher_v1.types.VodSession:
    """Gets a VOD session. VOD sessions are ephemeral resources that expire
    after a few hours.
    Args:
        project_id: The GCP project ID.
        location: The location of the session.
        session_id: The ID of the VOD session.

    Returns:
        The VOD session resource.
    """

    client = VideoStitcherServiceClient()

    name = client.vod_session_path(project_id, location, session_id)
    response = client.get_vod_session(name=name)
    print(f"VOD 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 API Ruby Video Stitcher API.

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

require "google/cloud/video/stitcher"

##
# Get a VOD session. VOD sessions are ephemeral resources that expire
# after a few hours.
#
# @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 VOD session ID (e.g. "my-vod-session-id")
#
def get_vod_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 VOD session.
  name = client.vod_session_path project: project_id, location: location,
                                 vod_session: session_id

  # Get the VOD session.
  session = client.get_vod_session name: name

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

Langkah selanjutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat browser contoh Google Cloud.