删除 VOD 配置

删除视频拼接器 VOD 配置资源。

深入探索

如需查看包含此代码示例的详细文档,请参阅以下内容:

代码示例

C#

在尝试此示例之前,请按照C# Video Stitcher API 快速入门:使用 客户端库。 有关详情,请参阅 Video Stitcher API C# API 参考文档

如需向 Video Stitcher API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


using Google.Cloud.Video.Stitcher.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;
using System.Threading.Tasks;

public class DeleteVodConfigSample
{
    public async Task DeleteVodConfigAsync(
        string projectId, string location, string vodConfigId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        DeleteVodConfigRequest request = new DeleteVodConfigRequest
        {
            VodConfigName = VodConfigName.FromProjectLocationVodConfig(projectId, location, vodConfigId)
        };

        // Make the request.
        Operation<Empty, OperationMetadata> response = await client.DeleteVodConfigAsync(request);

        // Poll until the returned long-running operation is complete.
        await response.PollUntilCompletedAsync();
    }
}

Go

在尝试此示例之前,请按照Go Video Stitcher API 快速入门:使用 客户端库。 有关详情,请参阅 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"
)

// deleteVodConfig deletes a previously-created VOD config.
func deleteVodConfig(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.DeleteVodConfigRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/vodConfigs/%s", projectID, location, vodConfigID),
	}
	// Deletes the VOD config.
	op, err := client.DeleteVodConfig(ctx, req)
	if err != nil {
		return fmt.Errorf("client.DeleteVodConfig: %w", err)
	}
	err = op.Wait(ctx)
	if err != nil {
		return err
	}

	fmt.Fprintf(w, "Deleted VOD config")
	return nil
}

Java

在试用此示例之前,请按照 Video Stitcher API 快速入门:使用客户端库中的 Java 设置说明进行操作。 如需了解详情,请参阅 Video Stitcher API Java API 参考文档

如需向 Video Stitcher API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


import com.google.cloud.video.stitcher.v1.DeleteVodConfigRequest;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import com.google.cloud.video.stitcher.v1.VodConfigName;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class DeleteVodConfig {

  private static final int TIMEOUT_IN_MINUTES = 2;

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

    deleteVodConfig(projectId, location, vodConfigId);
  }

  // Deletes a video on demand (VOD) config.
  public static void deleteVodConfig(String projectId, String location, String vodConfigId)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // 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()) {
      DeleteVodConfigRequest deleteVodConfigRequest =
          DeleteVodConfigRequest.newBuilder()
              .setName(VodConfigName.of(projectId, location, vodConfigId).toString())
              .build();

      videoStitcherServiceClient
          .deleteVodConfigAsync(deleteVodConfigRequest)
          .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES);
      System.out.println("Deleted VOD config");
    }
  }
}

Node.js

在尝试此示例之前,请按照Node.js Video Stitcher API 快速入门:使用 客户端库。 如需了解详情,请参阅 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 deleteVodConfig() {
  // Construct request
  const request = {
    name: stitcherClient.vodConfigPath(projectId, location, vodConfigId),
  };
  const [operation] = await stitcherClient.deleteVodConfig(request);
  await operation.promise();
  console.log('Deleted VOD config');
}

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

PHP

在尝试此示例之前,请按照PHP Video Stitcher API 快速入门:使用 客户端库。 有关详情,请参阅 Video Stitcher API PHP API 参考文档

如需向 Video Stitcher API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

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

/**
 * Deletes a VOD config.
 *
 * @param string $callingProjectId     The project ID to run the API call under
 * @param string $location             The location of the VOD config
 * @param string $vodConfigId         The ID of the VOD config
 */
function delete_vod_config(
    string $callingProjectId,
    string $location,
    string $vodConfigId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->vodConfigName($callingProjectId, $location, $vodConfigId);
    $request = (new DeleteVodConfigRequest())
        ->setName($formattedName);
    $operationResponse = $stitcherClient->deleteVodConfig($request);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        // Print status
        printf('Deleted VOD config %s' . PHP_EOL, $vodConfigId);
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
}

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 (
    VideoStitcherServiceClient,
)
from google.protobuf import empty_pb2 as empty


def delete_vod_config(
    project_id: str, location: str, vod_config_id: str
) -> empty.Empty:
    """Deletes a VOD config.
    Args:
        project_id: The GCP project ID.
        location: The location of the VOD config.
        vod_config_id: The user-defined VOD config ID."""

    client = VideoStitcherServiceClient()

    name = f"projects/{project_id}/locations/{location}/vodConfigs/{vod_config_id}"
    operation = client.delete_vod_config(name=name)
    response = operation.result()
    print("Deleted VOD config")
    return response

Ruby

在尝试此示例之前,请按照Ruby Video Stitcher API 快速入门:使用 客户端库。 有关详情,请参阅 Video Stitcher API Ruby API 参考文档

如需向 Video Stitcher API 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

require "google/cloud/video/stitcher"

##
# Delete a VOD config
#
# @param project_id [String] Your Google Cloud project (e.g. `my-project`)
# @param location [String] The location (e.g. `us-central1`)
# @param vod_config_id [String] Your VOD config name (e.g. `my-vod-config`)
#
def delete_vod_config project_id:, location:, vod_config_id:
  # Create a Video Stitcher client.
  client = Google::Cloud::Video::Stitcher.video_stitcher_service

  # Build the resource name of the VOD config.
  name = client.vod_config_path project: project_id, location: location,
                                vod_config: vod_config_id

  # Delete the VOD config.
  operation = client.delete_vod_config name: name

  # The returned object is of type Gapic::Operation. You can use this
  # object to check the status of an operation, cancel it, or wait
  # for results. Here is how to block until completion:
  operation.wait_until_done!

  # Print a success message.
  puts "Deleted VOD config"
end

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器