管理 VOD 工作階段

使用 Video Stitcher API 時,您每次在將廣告動態插入用戶端裝置前,都會建立隨選影片 (VOD) 工作階段。建立工作階段時,回應會包含播放網址,以及插入影片的廣告相關資訊。

本頁說明如何建立及管理未啟用 Google Ad Manager 的隨選視訊工作階段。如要進一步瞭解這類 VOD 工作階段,請參閱「管理透過 Google Ad Manager 啟用的 VOD 工作階段」。

事前準備

建立課程

如要為廣告縫合影片建立工作階段,請使用 projects.locations.vodSessions.create 方法。

建立 VOD 工作階段時,必須填寫下列欄位:

  • adTracking:判斷用戶端播放器是否應觸發播放和活動事件,或 Video Stitcher API 是否應代表用戶端播放器觸發播放事件;如要進一步瞭解用戶端廣告追蹤,請參閱「處理 VOD 用戶端廣告追蹤」。

    本節範例使用伺服器端廣告追蹤。

建立 VOD 工作階段時,下列欄位為選填:

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_NUMBER:IAM 設定頁面「專案編號」欄位中的 Google Cloud 專案編號
  • LOCATION:建立工作階段的位置;請使用支援的區域
    顯示地區
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • VOD_CONFIG_ID:使用者定義的隨選影片設定 ID

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/vodSessions/SESSION_ID",
  "interstitials": {
    "sessionContent": {
      "duration": "60s"
    }
  },
  "playUri": "PLAY_URI", # This is the ad-stitched VOD URI
  "sourceUri": "VOD_URI",
  "adTagUri": "AD_TAG_URI",
  "assetId": "ASSET_ID",
  "adTracking": "SERVER",
  "vodConfig": "projects/PROJECT_NUMBER/locations/LOCATION/vodConfigs/VOD_CONFIG_ID"
}

C#

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 C# 設定說明操作。詳情請參閱「Video Stitcher API C# API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


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

public class CreateVodSessionSample
{
    public VodSession CreateVodSession(
        string projectId, string location, string vodConfigId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        CreateVodSessionRequest request = new CreateVodSessionRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation(projectId, location),
            VodSession = new VodSession
            {
                VodConfig = VodConfigName.FormatProjectLocationVodConfig(projectId, location, vodConfigId),
                AdTracking = AdTracking.Server
            }
        };

        // Call the API.
        VodSession session = client.CreateVodSession(request);

        // Return the result.
        return session;
    }
}

Go

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Go 設定說明操作。詳情請參閱「Video Stitcher API Go API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

import (
	"context"
	"fmt"
	"io"

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

// createVodSession creates a video on demand (VOD) session in which to insert ads.
// VOD sessions are ephemeral resources that expire after a few hours.
func createVodSession(w io.Writer, projectID, vodConfigID string) error {
	// projectID := "my-project-id"
	// vodConfigID := "my-vod-config-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.CreateVodSessionRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, location),
		VodSession: &stitcherstreampb.VodSession{
			VodConfig:  fmt.Sprintf("projects/%s/locations/%s/vodConfigs/%s", projectID, location, vodConfigID),
			AdTracking: stitcherstreampb.AdTracking_SERVER,
		},
	}
	// Creates the VOD session.
	response, err := client.CreateVodSession(ctx, req)
	if err != nil {
		return fmt.Errorf("client.CreateVodSession: %w", err)
	}

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

Java

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Java 設定說明操作。詳情請參閱「Video Stitcher API Java API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


import com.google.cloud.video.stitcher.v1.AdTracking;
import com.google.cloud.video.stitcher.v1.CreateVodSessionRequest;
import com.google.cloud.video.stitcher.v1.LocationName;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import com.google.cloud.video.stitcher.v1.VodConfigName;
import com.google.cloud.video.stitcher.v1.VodSession;
import java.io.IOException;

public class CreateVodSession {

  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 vodConfigId = "my-vod-config-id";

    createVodSession(projectId, location, vodConfigId);
  }

  // Creates a video on demand (VOD) session using the parameters in the designated VOD config.
  // For more information, see
  // https://cloud.google.com/video-stitcher/docs/how-to/creating-vod-sessions.
  public static VodSession createVodSession(String projectId, String location, String vodConfigId)
      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.
    try (VideoStitcherServiceClient videoStitcherServiceClient =
        VideoStitcherServiceClient.create()) {
      CreateVodSessionRequest createVodSessionRequest =
          CreateVodSessionRequest.newBuilder()
              .setParent(LocationName.of(projectId, location).toString())
              .setVodSession(
                  VodSession.newBuilder()
                      .setVodConfig(VodConfigName.format(projectId, location, vodConfigId))
                      .setAdTracking(AdTracking.SERVER)
                      .build())
              .build();

      VodSession response = videoStitcherServiceClient.createVodSession(createVodSessionRequest);
      System.out.println("Created VOD session: " + response.getName());
      return response;
    }
  }
}

Node.js

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Node.js 設定說明操作。詳情請參閱「Video Stitcher API Node.js API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

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

async function createVodSession() {
  // Construct request
  const request = {
    parent: stitcherClient.locationPath(projectId, location),
    vodSession: {
      vodConfig: stitcherClient.vodConfigPath(
        projectId,
        location,
        vodConfigId
      ),
      adTracking: 'SERVER',
    },
  };
  const [session] = await stitcherClient.createVodSession(request);
  console.log(`VOD session: ${session.name}`);
}

createVodSession().catch(err => {
  console.error(err.message);
  process.exitCode = 1;
});

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Python 設定說明操作。詳情請參閱「Video Stitcher API Python API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


import argparse

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


def create_vod_session(
    project_id: str, location: str, vod_config_id: str
) -> stitcher_v1.types.VodSession:
    """Creates a VOD session. VOD sessions are ephemeral resources that expire
    after a few hours.
    Args:
        project_id: The GCP project ID.
        location: The location in which to create the session.
        vod_config_id: The user-defined VOD config ID to use to create the
                        session.

    Returns:
        The VOD session resource.
    """

    client = VideoStitcherServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    vod_config_name = (
        f"projects/{project_id}/locations/{location}/vodConfigs/{vod_config_id}"
    )

    vod_session = stitcher_v1.types.VodSession(
        vod_config=vod_config_name, ad_tracking="SERVER"
    )

    response = client.create_vod_session(parent=parent, vod_session=vod_session)
    print(f"VOD session: {response.name}")
    return response

Video Stitcher API 會為每個要求產生專屬工作階段 ID。工作階段會在 4 小時後過期。

廣告必須先經過編碼,才能縫合到隨選視訊工作階段。為廣告縫合影片建立工作階段時,Video Stitcher API 會判斷廣告是否已從上一個工作階段編碼。如果已插入,JSON 回應會指出廣告插播事件。API 只會尋找與 Google Cloud 專案相關聯的會期所建立的編碼廣告。如要進一步瞭解這個程序,請參閱「總覽」。

查看 JSON 回應。這項回應表示廣告未併入工作階段。如果發生這種情況,請等待 5 分鐘 (廣告編碼),然後重新執行 create session 指令。現在的回應應類似以下內容:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/vodSessions/SESSION_ID",
  "interstitials": {
    "adBreaks": [
      {
        "progressEvents": [
          {
            "timeOffset": "0s",
            "events": [
              {
                "type": "IMPRESSION",
                "uri": "https://securepubads.g.doubleclick.net/pcs/view..."
              },
              {
                "type": "START",
                "uri": "https://pubads.g.doubleclick.net/pagead/interaction/..."
              },
              ...
            ]
          },
          ...
        ],
        "ads": [
          {
            "duration": "10s",
            "activityEvents": [
              {
                "type": "ERROR",
                "uri": "https://pubads.g.doubleclick.net/pagead/interaction/..."
              },
              {
                "type": "CLICK_THROUGH",
                "uri": "https://pubads.g.doubleclick.net/pcs/click...",
                "id": "GDFP"
              },
              ...
            ]
          }
        ],
        "endTimeOffset": "10s",
        "startTimeOffset": "0s"
      }
    ],
    "sessionContent": {
      "duration": "70s"
    }
  },
  "playUri": "PLAY_URI",
  "sourceUri": "VOD_URI",
  "adTagUri": "AD_TAG_URI",
  "assetId": "ASSET_ID",
  "adTracking": "SERVER",
  "vodConfig": "projects/PROJECT_NUMBER/locations/LOCATION/vodConfigs/VOD_CONFIG_ID"
}

回應是 VOD 會議物件,包含下列欄位:

如果您要代表顧客的裝置產生工作階段,請使用 HTTP 標頭設定下列參數:

參數 HTTP 標頭
CLIENT_IP x-user-ip
REFERRER_URL referer
USER_AGENT user-agent

您可以在上述 curl 要求中新增下列標頭:

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

廣告代碼巨集

廣告代碼可以包含巨集,因此每個工作階段的廣告代碼可能都不相同。廣告代碼中的巨集會以方括號表示,如下例所示:

AD_TAG_URI&macro=[my-key]

adTagUri 是在 VOD 設定中定義。

如要替換廣告代碼巨集中的值,請在 adTagMacroMap 欄位中提供對應。舉例來說,如要將 [my-key] 巨集替換為字串 my-value,請提供下列資訊:

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

Video Stitcher API 要求廣告中繼資料時,會使用下列廣告代碼:

AD_TAG_URI&macro=my-value

取得工作階段

如要取得廣告縫合影片的工作階段,請使用 projects.locations.vodSessions.get 方法。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_NUMBER:IAM 設定頁面「專案編號」欄位中的 Google Cloud 專案編號
  • LOCATION:工作階段的位置;請使用支援的區域之一
    顯示地區
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • SESSION_ID:隨選影片工作階段的 ID

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/vodSessions/SESSION_ID",
  "interstitials": {
    "adBreaks": [
      {
        "progressEvents": [
          {
            "timeOffset": "0s",
            "events": [
              {
                "type": "IMPRESSION",
                "uri": "https://securepubads.g.doubleclick.net/pcs/view..."
              },
              {
                "type": "START",
                "uri": "https://pubads.g.doubleclick.net/pagead/interaction/..."
              },
              ...
            ]
          },
          ...
        ],
        "ads": [
          {
            "duration": "10s",
            "activityEvents": [
              {
                "type": "ERROR",
                "uri": "https://pubads.g.doubleclick.net/pagead/interaction/..."
              },
              {
                "type": "CLICK_THROUGH",
                "uri": "https://pubads.g.doubleclick.net/pcs/click...",
                "id": "GDFP"
              },
              ...
            ]
          }
        ],
        "endTimeOffset": "10s",
        "startTimeOffset": "0s"
      }
    ],
    "sessionContent": {
      "duration": "70s"
    }
  },
  "playUri": "PLAY_URI",
  "sourceUri": "VOD_URI",
  "adTagUri": "AD_TAG_URI",
  "assetId": "ASSET_ID",
  "adTracking": "SERVER",
  "vodConfig": "projects/PROJECT_NUMBER/locations/LOCATION/vodConfigs/VOD_CONFIG_ID"
}

C#

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 C# 設定說明操作。詳情請參閱「Video Stitcher API C# API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


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

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Go 設定說明操作。詳情請參閱「Video Stitcher API Go API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Java 設定說明操作。詳情請參閱「Video Stitcher API Java API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


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);
  }

  // Gets a video on demand (VOD) session.
  public static VodSession 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.
    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());
      return response;
    }
  }
}

Node.js

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Node.js 設定說明操作。詳情請參閱「Video Stitcher API Node.js API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

/**
 * 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().catch(err => {
  console.error(err.message);
  process.exitCode = 1;
});

PHP

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 PHP 設定說明操作。詳情請參閱「Video Stitcher API PHP API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Python 設定說明操作。詳情請參閱「Video Stitcher API Python API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


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

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Ruby 設定說明操作。詳情請參閱「Video Stitcher API Ruby API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

廣告插入播放清單的範例

以下顯示廣告縫合前的來源 VOD 播放清單範例:

#EXTM3U
#EXT-X-TARGETDURATION:6
#EXT-X-VERSION:4
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:6.000,
segment_01.ts
#EXTINF:6.000,
segment_02.ts
#EXTINF:6.000,
segment_03.ts
#EXTINF:6.000,
segment_04.ts
#EXTINF:6.000,
segment_05.ts
#EXTINF:6.000,
segment_06.ts
#EXT-X-ENDLIST

以下顯示在廣告縫合後,含有片頭、片中和片尾廣告的 VOD 播放清單來源範例:

#EXTM3U
#EXT-X-VERSION:4
#EXT-X-TARGETDURATION:6
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-DISCONTINUITY
#EXTINF:4.000,
https://ads.us-west1.cdn.videostitcher.goog/preroll_ad/seg_01.ts
#EXTINF:4.000,
https://ads.us-west1.cdn.videostitcher.goog/preroll_ad/seg_02.ts
#EXTINF:1.990,
https://ads.us-west1.cdn.videostitcher.goog/preroll_ad/seg_03.ts
#EXT-X-DISCONTINUITY
#EXTINF:6.000,
segment_01.ts
#EXTINF:6.000,
segment_02.ts
#EXT-X-DISCONTINUITY
#EXTINF:4.000,
https://ads.us-west1.cdn.videostitcher.goog/midroll_ad/seg_01.ts
#EXTINF:0.990,
https://ads.us-west1.cdn.videostitcher.goog/midroll_ad/seg_02.ts
#EXT-X-DISCONTINUITY
#EXTINF:6.000,
segment_03.ts
#EXTINF:6.000,
segment_04.ts
#EXTINF:6.000,
segment_05.ts
#EXTINF:6.000,
segment_06.ts
#EXT-X-DISCONTINUITY
#EXTINF:4.000,
https://ads.us-west1.cdn.videostitcher.goog/postroll_ad/seg_01.ts
#EXTINF:4.000,
https://ads.us-west1.cdn.videostitcher.goog/postroll_ad/seg_02.ts
#EXTINF:1.990,
https://ads.us-west1.cdn.videostitcher.goog/postroll_ad/seg_03.ts
#EXT-X-ENDLIST

處理用戶端廣告追蹤

啟用用戶端廣告追蹤功能後,播放器會負責觸發廣告追蹤事件。建立 VOD 工作階段時,系統會傳回插頁式廣告物件,您可以在該物件中找到用戶端追蹤資訊。

插頁式廣告物件包含廣告追蹤資訊,以及從廣告代碼請求剖析的隨播廣告中繼資料。如要檢查拼接的廣告,請參閱「檢查 VOD 工作階段」。

插頁式廣告

廣告追蹤資訊會依廣告插播時間分組,並放在 interstitials 物件中。

廣告插播可能會有進度事件,指定每個已觸發事件的事件 URI 和相對於插播開始時間的時間偏移。如要進一步瞭解進度事件,請參閱 ProgressEvent 參考文件。

廣告插播也可能包含活動事件和隨播廣告。如要進一步瞭解隨播廣告,請參閱 CompanionAds 參考說明文件。

以下是插頁式廣告範例:

{
  "adBreaks": [
    {
      "progressEvents": [
        {
          "timeOffset": "0s",
          "events": [
            {
              "type": "IMPRESSION",
              "uri": "https://example.com/impression"
            },
            {
              "type": "START",
              "uri": "https://example.com/start"
            }
          ]
        },
        {
          "timeOffset": "1.250s",
          "events": [
            {
              "type": "FIRST_QUARTILE",
              "uri": "https://example.com/firstquartile"
            }
          ]
        }
      ],
      "ads": [
        {
          "duration": "5s",
          "activityEvents": [
            {
              "type": "PAUSE",
              "uri": "https://example.com/pause"
            }
          ],
          "companionAds": {
            "required": "all",
            "companions": [
              {
                "width": 200,
                "height": 100,
                "staticResource": {
                  "uri": "https://example.com/static.png",
                  "creativeType": "image/png"
                }
              }
            ]
          }
        },
        {
          "duration": "10s"
        }
      ],
      "startTimeOffset": "0s",
      "endTimeOffset": "15.000s"
    }
  ],
  "sessionContent": {
      "duration": "120.000s"
  }
}

在上述範例中,有一個片頭廣告插播時間點,其中有兩個廣告已縫合到 VOD 資產中。第一則廣告的長度為 5 秒,第二則廣告的長度為 10 秒。如 duration 欄位在 sessionContent 中所指,拼接影片總長度為 120 秒。

用戶端收到這個物件時,應執行下列操作:

  • 在廣告插播開始時,向 https://example.com/start 發出要求。
  • 在廣告插播開始時,向 https://example.com/impression 發出要求。
  • 每當觀眾在第一個廣告播放期間暫停影片,請向 https://example.com/pause 發出請求。
  • 在第一個廣告開始播放 1.25 秒後發出要求。https://example.com/firstQuartile
  • 在第一則廣告期間載入隨播廣告 https://example.com/static.png。

檢查 VOD 工作階段

本節說明如何檢查特定 VOD 工作階段的廣告代碼詳細資料和拼接詳細資料。詳情請參閱 VodAdTagDetail 和 VodStitchDetail 的 REST 說明文件。

VOD 工作階段的 VOD 設定中定義的 adTagUri 欄位,會指定要從哪個網址擷取廣告中繼資料。Video Stitcher API 發出要求時,也會包含使用者中繼資料。

/vodAdTagDetails 端點包含下列資訊:

  • 已解析的廣告代碼
  • 使用者中繼資料
  • 要求主體和標頭
  • 回應內文和標頭

/vodStitchDetails 端點包含下列資訊:

  • 廣告插播 ID
  • 廣告 ID
  • 廣告時間偏移 (以秒為單位)
  • 廣告未插入的原因
  • 廣告媒體中繼資料

列出廣告代碼詳細資料

如要列出 VOD 工作階段的廣告代碼詳細資料,請使用 projects.locations.vodSessions.vodAdTagDetails.list 方法。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_NUMBER:IAM 設定頁面「專案編號」欄位中的 Google Cloud 專案編號
  • LOCATION:工作階段的位置;請使用支援的區域之一
    顯示地區
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • SESSION_ID:隨選影片工作階段的 ID

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "vodAdTagDetails" : [
    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/vodSessions/SESSION_ID/vodAdTagDetails/VOD_AD_TAG_DETAILS_ID",
      "adRequests": [
        {
          "uri": "REQUEST_URL",
          "requestMetadata": "AD_TAG_REQUEST_METADATA",
          "responseMetadata": "AD_TAG_RESPONSE_METADATA"
        }
      ]
    }
  ]
}

C#

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 C# 設定說明操作。詳情請參閱「Video Stitcher API C# API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


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

public class ListVodAdTagDetailsSample
{
    public PagedEnumerable<ListVodAdTagDetailsResponse, VodAdTagDetail> ListVodAdTagDetails(
        string projectId, string regionId, string sessionId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        ListVodAdTagDetailsRequest request = new ListVodAdTagDetailsRequest
        {
            ParentAsVodSessionName = VodSessionName.FromProjectLocationVodSession(projectId, regionId, sessionId)
        };

        // Make the request.
        PagedEnumerable<ListVodAdTagDetailsResponse, VodAdTagDetail> response = client.ListVodAdTagDetails(request);
        foreach (VodAdTagDetail vodAdTagDetail in response)
        {
            Console.WriteLine($"{vodAdTagDetail.Name}");
        }

        // Return the result.
        return response;
    }
}

Go

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Go 設定說明操作。詳情請參閱「Video Stitcher API Go API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

// listVodAdTagDetails lists the ad tag details for a video on demand (VOD) session.
func listVodAdTagDetails(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.ListVodAdTagDetailsRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s/vodSessions/%s", projectID, location, sessionID),
	}

	it := client.ListVodAdTagDetails(ctx, req)
	fmt.Fprintln(w, "VOD 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

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Java 設定說明操作。詳情請參閱「Video Stitcher API Java API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


import com.google.cloud.video.stitcher.v1.ListVodAdTagDetailsRequest;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListVodAdTagDetailsPagedResponse;
import com.google.cloud.video.stitcher.v1.VodAdTagDetail;
import com.google.cloud.video.stitcher.v1.VodSessionName;
import java.io.IOException;

public class ListVodAdTagDetails {

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

    listVodAdTagDetails(projectId, location, sessionId);
  }

  // Lists the ad tag details for a video on demand (VOD) session.
  public static ListVodAdTagDetailsPagedResponse listVodAdTagDetails(
      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.
    try (VideoStitcherServiceClient videoStitcherServiceClient =
        VideoStitcherServiceClient.create()) {
      ListVodAdTagDetailsRequest listVodAdTagDetailsRequest =
          ListVodAdTagDetailsRequest.newBuilder()
              .setParent(VodSessionName.of(projectId, location, sessionId).toString())
              .build();

      VideoStitcherServiceClient.ListVodAdTagDetailsPagedResponse response =
          videoStitcherServiceClient.listVodAdTagDetails(listVodAdTagDetailsRequest);

      System.out.println("VOD ad tag details:");
      for (VodAdTagDetail adTagDetail : response.iterateAll()) {
        System.out.println(adTagDetail.toString());
      }
      return response;
    }
  }
}

Node.js

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Node.js 設定說明操作。詳情請參閱「Video Stitcher API Node.js API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

/**
 * 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 listVodAdTagDetails() {
  // Construct request
  const request = {
    parent: stitcherClient.vodSessionPath(projectId, location, sessionId),
  };
  const iterable = await stitcherClient.listVodAdTagDetailsAsync(request);
  console.log('VOD ad tag details:');
  for await (const response of iterable) {
    console.log(response.name);
  }
}

listVodAdTagDetails().catch(err => {
  console.error(err.message);
  process.exitCode = 1;
});

PHP

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 PHP 設定說明操作。詳情請參閱「Video Stitcher API PHP API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

/**
 * Lists the ad tag details for the specified 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 list_vod_ad_tag_details(
    string $callingProjectId,
    string $location,
    string $sessionId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->vodSessionName($callingProjectId, $location, $sessionId);
    $request = (new ListVodAdTagDetailsRequest())
        ->setParent($formattedName);
    $response = $stitcherClient->listVodAdTagDetails($request);

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

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Python 設定說明操作。詳情請參閱「Video Stitcher API Python API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


import argparse

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


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

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

    client = VideoStitcherServiceClient()

    parent = client.vod_session_path(project_id, location, session_id)
    page_result = client.list_vod_ad_tag_details(parent=parent)
    print("VOD ad tag details:")
    for response in page_result:
        print(response)

    return response

Ruby

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Ruby 設定說明操作。詳情請參閱「Video Stitcher API Ruby API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

require "google/cloud/video/stitcher"

##
# List the ad tag details for a VOD 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 VOD session ID (e.g. `my-vod-session-id`)
#
def list_vod_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.vod_session_path project: project_id, location: location,
                                   vod_session: session_id

  # List all ad tag details for the VOD session.
  response = client.list_vod_ad_tag_details parent: parent

  puts "VOD ad tag details:"
  # Print out all VOD ad tag details.
  response.each do |vod_ad_tag_detail|
    puts vod_ad_tag_detail.name
  end
end

回應會傳回 VodAdTagDetail 物件清單。每個 VodAdTagDetail 代表廣告代碼的廣告擷取中繼資料,每個 AdRequest 代表單一廣告請求的廣告請求中繼資料。

額外結果

curl 回應可能包含 nextPageToken,可用於擷取其他結果:

{
  "vodAdTagDetails": [
    ...
  ],
  "nextPageToken": "NEXT_PAGE_TOKEN"
}

您可以傳送另一個 curl 要求 (包括 NEXT_PAGE_TOKEN 值),列出其他物件。在上述 API 呼叫的網址中附加下列內容:

?pageToken=NEXT_PAGE_TOKEN

取得廣告代碼詳細資料

如要取得 VOD 工作階段中單一 VodAdTagDetail 物件的詳細資料,請使用 projects.locations.vodSessions.vodAdTagDetails.get 方法。

以下範例說明如何使用先前要求傳回的廣告代碼詳細資料名稱,查看 VOD 會議的單一廣告代碼詳細資料:

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_NUMBER:IAM 設定頁面「專案編號」欄位中的 Google Cloud 專案編號
  • LOCATION:工作階段的位置;請使用支援的區域之一
    顯示地區
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • SESSION_ID:隨選影片工作階段的 ID
  • VOD_AD_TAG_DETAILS_ID:隨選影片廣告代碼詳細資料的 ID

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/vodSessions/SESSION_ID/vodAdTagDetails/VOD_AD_TAG_DETAILS_ID",
  "adRequests": [
    {
      "uri": "REQUEST_URL",
      "requestMetadata": "AD_TAG_REQUEST_METADATA",
      "responseMetadata": "AD_TAG_RESPONSE_METADATA"
    }
  ]
}

C#

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 C# 設定說明操作。詳情請參閱「Video Stitcher API C# API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


using Google.Cloud.Video.Stitcher.V1;

public class GetVodAdTagDetailSample
{
    public VodAdTagDetail GetVodAdTagDetail(
        string projectId, string location, string sessionId, string adTagDetailId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        GetVodAdTagDetailRequest request = new GetVodAdTagDetailRequest
        {
            VodAdTagDetailName = VodAdTagDetailName.FromProjectLocationVodSessionVodAdTagDetail(projectId, location, sessionId, adTagDetailId)
        };

        // Call the API.
        VodAdTagDetail vodAdTagDetail = client.GetVodAdTagDetail(request);

        // Return the result.
        return vodAdTagDetail;
    }
}

Go

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Go 設定說明操作。詳情請參閱「Video Stitcher API Go API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

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

// getVodAdTagDetail gets the specified ad tag detail for a video on demand (VOD) session.
func getVodAdTagDetail(w io.Writer, projectID, sessionID, adTagDetailID string) error {
	// projectID := "my-project-id"
	// sessionID := "123-456-789"
	// adTagDetailID := "01234-56789"
	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.GetVodAdTagDetailRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/vodSessions/%s/vodAdTagDetails/%s", projectID, location, sessionID, adTagDetailID),
	}
	// Gets the ad tag detail.
	response, err := client.GetVodAdTagDetail(ctx, req)
	if err != nil {
		return fmt.Errorf("client.GetVodAdTagDetail: %w", err)
	}
	b, err := json.MarshalIndent(response, "", " ")
	if err != nil {
		return fmt.Errorf("json.MarshalIndent: %w", err)
	}

	fmt.Fprintf(w, "VOD ad tag detail:\n%s", string(b))
	return nil
}

Java

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Java 設定說明操作。詳情請參閱「Video Stitcher API Java API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


import com.google.cloud.video.stitcher.v1.GetVodAdTagDetailRequest;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import com.google.cloud.video.stitcher.v1.VodAdTagDetail;
import com.google.cloud.video.stitcher.v1.VodAdTagDetailName;
import java.io.IOException;

public class GetVodAdTagDetail {

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

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

  // Gets an ad tag detail for a video on demand (VOD) session.
  public static VodAdTagDetail getVodAdTagDetail(
      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.
    try (VideoStitcherServiceClient videoStitcherServiceClient =
        VideoStitcherServiceClient.create()) {
      GetVodAdTagDetailRequest getVodAdTagDetailRequest =
          GetVodAdTagDetailRequest.newBuilder()
              .setName(
                  VodAdTagDetailName.of(projectId, location, sessionId, adTagDetailId).toString())
              .build();

      VodAdTagDetail response =
          videoStitcherServiceClient.getVodAdTagDetail(getVodAdTagDetailRequest);
      System.out.println("VOD ad tag detail: " + response.getName());
      return response;
    }
  }
}

Node.js

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Node.js 設定說明操作。詳情請參閱「Video Stitcher API Node.js API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

/**
 * 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 getVodAdTagDetail() {
  // Construct request
  const request = {
    name: stitcherClient.vodAdTagDetailPath(
      projectId,
      location,
      sessionId,
      adTagDetailId
    ),
  };
  const [adTagDetail] = await stitcherClient.getVodAdTagDetail(request);
  console.log(`VOD ad tag detail: ${adTagDetail.name}`);
}

getVodAdTagDetail().catch(err => {
  console.error(err.message);
  process.exitCode = 1;
});

PHP

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 PHP 設定說明操作。詳情請參閱「Video Stitcher API PHP API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

/**
 * Gets the specified ad tag detail for the 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
 * @param string $adTagDetailId        The ID of the ad tag detail
 */
function get_vod_ad_tag_detail(
    string $callingProjectId,
    string $location,
    string $sessionId,
    string $adTagDetailId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->vodAdTagDetailName($callingProjectId, $location, $sessionId, $adTagDetailId);
    $request = (new GetVodAdTagDetailRequest())
        ->setName($formattedName);
    $adTagDetail = $stitcherClient->getVodAdTagDetail($request);

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

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Python 設定說明操作。詳情請參閱「Video Stitcher API Python API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


import argparse

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


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

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

    client = VideoStitcherServiceClient()

    name = client.vod_ad_tag_detail_path(
        project_id, location, session_id, ad_tag_detail_id
    )
    response = client.get_vod_ad_tag_detail(name=name)
    print(f"VOD ad tag detail: {response.name}")
    return response

Ruby

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Ruby 設定說明操作。詳情請參閱「Video Stitcher API Ruby API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

require "google/cloud/video/stitcher"

##
# Get the specified ad tag detail for a VOD 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 VOD session ID (e.g. `my-vod-session-id`)
# @param ad_tag_detail_id [String] The ad tag detail ID (e.g. `my-ad-tag-id`)
#
def get_vod_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 VOD ad tag detail.
  name = client.vod_ad_tag_detail_path project: project_id, location: location,
                                       vod_session: session_id,
                                       vod_ad_tag_detail: ad_tag_detail_id

  # Get the VOD ad tag detail.
  ad_tag_detail = client.get_vod_ad_tag_detail name: name

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

列出拼接詳細資料

您可以查看任何 VOD 工作階段的縫合廣告詳細資訊。

如要列出 VOD 工作階段的縫合詳細資料,請使用 projects.locations.vodSessions.vodStitchDetails.list 方法。

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_NUMBER:IAM 設定頁面「專案編號」欄位中的 Google Cloud 專案編號
  • LOCATION:工作階段的位置;請使用支援的區域之一
    顯示地區
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • SESSION_ID:隨選影片工作階段的 ID

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "vodStitchDetails" : [
    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/vodSessions/SESSION_ID/vodStitchDetails/VOD_STITCH_DETAILS_ID",
      "adStitchDetails": [
        {
          "adBreakId": "AD_BREAK_ID",
          "adId": "AD_ID",
          "adTimeOffset": "AD_TIME_OFFSET",
          "skipReason": "SKIP_REASON",
          "media": "MEDIA_OBJECT"
        },
        {
          "adBreakId": "my-other-ad-break-id",
          "adId": "my-other-ad-id",
          "adTimeOffset": "my-other-ad-time-offset",
          "skipReason": "my-other-skip-reason",
          "media": "my-other-media-object"
        }
      ]
    }
  ]
}

C#

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 C# 設定說明操作。詳情請參閱「Video Stitcher API C# API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


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

public class ListVodStitchDetailsSample
{
    public PagedEnumerable<ListVodStitchDetailsResponse, VodStitchDetail> ListVodStitchDetails(
        string projectId, string regionId, string sessionId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        ListVodStitchDetailsRequest request = new ListVodStitchDetailsRequest
        {
            ParentAsVodSessionName = VodSessionName.FromProjectLocationVodSession(projectId, regionId, sessionId)
        };

        // Make the request.
        PagedEnumerable<ListVodStitchDetailsResponse, VodStitchDetail> response = client.ListVodStitchDetails(request);
        foreach (VodStitchDetail vodStitchDetail in response)
        {
            Console.WriteLine($"{vodStitchDetail.Name}");
        }

        // Return the result.
        return response;
    }
}

Go

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Go 設定說明操作。詳情請參閱「Video Stitcher API Go API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

// listVodStitchDetails lists the stitch details for a video on demand (VOD) session.
func listVodStitchDetails(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.ListVodStitchDetailsRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s/vodSessions/%s", projectID, location, sessionID),
	}

	it := client.ListVodStitchDetails(ctx, req)
	fmt.Fprintln(w, "VOD stitch 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

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Java 設定說明操作。詳情請參閱「Video Stitcher API Java API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


import com.google.cloud.video.stitcher.v1.ListVodStitchDetailsRequest;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListVodStitchDetailsPagedResponse;
import com.google.cloud.video.stitcher.v1.VodSessionName;
import com.google.cloud.video.stitcher.v1.VodStitchDetail;
import java.io.IOException;

public class ListVodStitchDetails {

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

    listVodStitchDetails(projectId, location, sessionId);
  }

  // Lists the VOD stitch details for a video on demand (VOD) session.
  public static ListVodStitchDetailsPagedResponse listVodStitchDetails(
      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.
    try (VideoStitcherServiceClient videoStitcherServiceClient =
        VideoStitcherServiceClient.create()) {
      ListVodStitchDetailsRequest listVodStitchDetailsRequest =
          ListVodStitchDetailsRequest.newBuilder()
              .setParent(VodSessionName.of(projectId, location, sessionId).toString())
              .build();

      VideoStitcherServiceClient.ListVodStitchDetailsPagedResponse response =
          videoStitcherServiceClient.listVodStitchDetails(listVodStitchDetailsRequest);

      System.out.println("VOD stitch details:");
      for (VodStitchDetail stitchDetail : response.iterateAll()) {
        System.out.println(stitchDetail.toString());
      }
      return response;
    }
  }
}

Node.js

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Node.js 設定說明操作。詳情請參閱「Video Stitcher API Node.js API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

/**
 * 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 listVodStitchDetails() {
  // Construct request
  const request = {
    parent: stitcherClient.vodSessionPath(projectId, location, sessionId),
  };
  const iterable = await stitcherClient.listVodStitchDetailsAsync(request);
  console.log('VOD stitch details:');
  for await (const response of iterable) {
    console.log(response.name);
  }
}

listVodStitchDetails().catch(err => {
  console.error(err.message);
  process.exitCode = 1;
});

PHP

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 PHP 設定說明操作。詳情請參閱「Video Stitcher API PHP API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

/**
 * Lists the stitch details for the specified 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 list_vod_stitch_details(
    string $callingProjectId,
    string $location,
    string $sessionId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->vodSessionName($callingProjectId, $location, $sessionId);
    $request = (new ListVodStitchDetailsRequest())
        ->setParent($formattedName);
    $response = $stitcherClient->listVodStitchDetails($request);

    // Print the stitch details list.
    $stitchDetails = $response->iterateAllElements();
    print('VOD stitch details:' . PHP_EOL);
    foreach ($stitchDetails as $stitchDetail) {
        printf('%s' . PHP_EOL, $stitchDetail->getName());
    }
}

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Python 設定說明操作。詳情請參閱「Video Stitcher API Python API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


import argparse

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


def list_vod_stitch_details(
    project_id: str, location: str, session_id: str
) -> pagers.ListVodStitchDetailsPager:
    """Lists the stitch details for the specified VOD session.
    Args:
        project_id: The GCP project ID.
        location: The location of the session.
        session_id: The ID of the VOD session.

    Returns:
        An iterable object containing VOD stitch details resources.
    """

    client = VideoStitcherServiceClient()

    parent = client.vod_session_path(project_id, location, session_id)
    page_result = client.list_vod_stitch_details(parent=parent)
    print("VOD stitch details:")
    for response in page_result:
        print(response)

    return response

Ruby

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Ruby 設定說明操作。詳情請參閱「Video Stitcher API Ruby API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

require "google/cloud/video/stitcher"

##
# List the stitch details for a VOD 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 VOD session ID (e.g. `my-vod-session-id`)
#
def list_vod_stitch_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.vod_session_path project: project_id, location: location,
                                   vod_session: session_id

  # List all stitch details for the VOD session.
  response = client.list_vod_stitch_details parent: parent

  puts "VOD stitch details:"
  # Print out all VOD stitch details.
  response.each do |vod_stitch_detail|
    puts vod_stitch_detail.name
  end
end

回應會傳回 VodStitchDetail 物件清單。每個 VodStitchDetail 代表廣告代碼的縫合詳細資料,每個 adStitchDetails 物件代表單一廣告的縫合詳細資料。

curl 回應可能包含 nextPageToken,可用於擷取其他結果。

取得廣告代碼拼接詳細資料

如要取得 VOD 工作階段中單一廣告代碼的縫合詳細資料,請使用 projects.locations.vodSessions.vodStitchDetails.get 方法。

以下範例說明如何使用先前要求傳回的拼接廣告代碼詳細資料名稱,查看 VOD 會期的單一廣告代碼拼接詳細資料:

REST

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_NUMBER:IAM 設定頁面「專案編號」欄位中的 Google Cloud 專案編號
  • LOCATION:工作階段的位置;請使用支援的區域之一
    顯示地區
    • us-central1
    • us-east1
    • us-west1
    • asia-east1
    • asia-south1
    • asia-southeast1
    • europe-west1
    • southamerica-east1
  • SESSION_ID:隨選影片工作階段的 ID
  • VOD_STITCH_DETAILS_ID:隨選影片拼接詳細資料的 ID

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/vodSessions/SESSION_ID/vodStitchDetails/VOD_STITCH_DETAILS_ID",
  "adStitchDetails": [
    {
      "adBreakId": "AD_BREAK_ID",
      "adId": "AD_ID",
      "adTimeOffset": "AD_TIME_OFFSET",
      "skipReason": "SKIP_REASON",
      "media": "MEDIA_OBJECT"
    }
  ]
}

C#

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 C# 設定說明操作。詳情請參閱「Video Stitcher API C# API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


using Google.Cloud.Video.Stitcher.V1;

public class GetVodStitchDetailSample
{
    public VodStitchDetail GetVodStitchDetail(
        string projectId, string location, string sessionId, string stitchDetailId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        GetVodStitchDetailRequest request = new GetVodStitchDetailRequest
        {
            VodStitchDetailName = VodStitchDetailName.FromProjectLocationVodSessionVodStitchDetail(projectId, location, sessionId, stitchDetailId)
        };

        // Call the API.
        VodStitchDetail vodStitchDetail = client.GetVodStitchDetail(request);

        // Return the result.
        return vodStitchDetail;
    }
}

Go

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Go 設定說明操作。詳情請參閱「Video Stitcher API Go API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

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

// getVodStitchDetail gets the specified stitch detail for a video on demand (VOD) session.
func getVodStitchDetail(w io.Writer, projectID, sessionID, stitchDetailID string) error {
	// projectID := "my-project-id"
	// sessionID := "123-456-789"
	// stitchDetailID := "01234-56789"
	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.GetVodStitchDetailRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/vodSessions/%s/vodStitchDetails/%s", projectID, location, sessionID, stitchDetailID),
	}
	// Gets the stitch detail.
	response, err := client.GetVodStitchDetail(ctx, req)
	if err != nil {
		return fmt.Errorf("client.GetStitchDetail: %w", err)
	}
	b, err := json.MarshalIndent(response, "", " ")
	if err != nil {
		return fmt.Errorf("json.MarshalIndent: %w", err)
	}

	fmt.Fprintf(w, "VOD stitch detail:\n%s", string(b))
	return nil
}

Java

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Java 設定說明操作。詳情請參閱「Video Stitcher API Java API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


import com.google.cloud.video.stitcher.v1.GetVodStitchDetailRequest;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import com.google.cloud.video.stitcher.v1.VodStitchDetail;
import com.google.cloud.video.stitcher.v1.VodStitchDetailName;
import java.io.IOException;

public class GetVodStitchDetail {

  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 stitchDetailId = "my-stitch-id";

    getVodStitchDetail(projectId, location, sessionId, stitchDetailId);
  }

  // Gets a stitch detail for a video on demand (VOD) session.
  public static VodStitchDetail getVodStitchDetail(
      String projectId, String location, String sessionId, String stitchDetailId)
      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.
    try (VideoStitcherServiceClient videoStitcherServiceClient =
        VideoStitcherServiceClient.create()) {
      GetVodStitchDetailRequest getVodStitchDetailRequest =
          GetVodStitchDetailRequest.newBuilder()
              .setName(
                  VodStitchDetailName.of(projectId, location, sessionId, stitchDetailId).toString())
              .build();

      VodStitchDetail response =
          videoStitcherServiceClient.getVodStitchDetail(getVodStitchDetailRequest);
      System.out.println("VOD stitch detail: " + response.getName());
      return response;
    }
  }
}

Node.js

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Node.js 設定說明操作。詳情請參閱「Video Stitcher API Node.js API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

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

async function getVodStitchDetail() {
  // Construct request
  const request = {
    name: stitcherClient.vodStitchDetailPath(
      projectId,
      location,
      sessionId,
      stitchDetailId
    ),
  };
  const [stitchDetail] = await stitcherClient.getVodStitchDetail(request);
  console.log(`VOD stitch detail: ${stitchDetail.name}`);
}

getVodStitchDetail().catch(err => {
  console.error(err.message);
  process.exitCode = 1;
});

PHP

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 PHP 設定說明操作。詳情請參閱「Video Stitcher API PHP API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

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

/**
 * Gets the specified stitch detail for the 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
 * @param string $stitchDetailId       The ID of the stitch detail
 */
function get_vod_stitch_detail(
    string $callingProjectId,
    string $location,
    string $sessionId,
    string $stitchDetailId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->vodStitchDetailName($callingProjectId, $location, $sessionId, $stitchDetailId);
    $request = (new GetVodStitchDetailRequest())
        ->setName($formattedName);
    $stitchDetail = $stitcherClient->getVodStitchDetail($request);

    // Print results
    printf('VOD stitch detail: %s' . PHP_EOL, $stitchDetail->getName());
}

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Python 設定說明操作。詳情請參閱「Video Stitcher API Python API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。


import argparse

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


def get_vod_stitch_detail(
    project_id: str, location: str, session_id: str, stitch_detail_id: str
) -> stitcher_v1.types.VodStitchDetail:
    """Gets the specified stitch detail for a VOD session.
    Args:
        project_id: The GCP project ID.
        location: The location of the session.
        session_id: The ID of the VOD session.
        stitch_detail_id: The ID of the stitch details.

    Returns:
        The VOD stitch detail resource.
    """

    client = VideoStitcherServiceClient()

    name = client.vod_stitch_detail_path(
        project_id, location, session_id, stitch_detail_id
    )
    response = client.get_vod_stitch_detail(name=name)
    print(f"VOD stitch detail: {response.name}")
    return response

Ruby

在試用這個範例之前,請先按照「使用用戶端程式庫的 Video Stitcher API 快速入門導覽課程」中的 Ruby 設定說明操作。詳情請參閱「Video Stitcher API Ruby API 參考文件」。

如要向 Video Stitcher API 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

require "google/cloud/video/stitcher"

##
# Get the specified stitch detail for a VOD 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 VOD session ID (e.g. `my-vod-session-id`)
# @param stitch_detail_id [String] The stitch detail ID (e.g. `my-stitch-id`)
#
def get_vod_stitch_detail project_id:, location:, session_id:, stitch_detail_id:
  # Create a Video Stitcher client.
  client = Google::Cloud::Video::Stitcher.video_stitcher_service

  # Build the resource name of the VOD stitch detail.
  name = client.vod_stitch_detail_path project: project_id, location: location,
                                       vod_session: session_id,
                                       vod_stitch_detail: stitch_detail_id

  # Get the VOD stitch detail.
  stitch_detail = client.get_vod_stitch_detail name: name

  # Print the VOD stitch detail name.
  puts "VOD stitch detail: #{stitch_detail.name}"
end