Menghapus template tugas

Menghapus template tugas transcoding.

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 Transcoder API menggunakan library klien. Untuk informasi selengkapnya, lihat Dokumentasi referensi API C# Transcoder API.

Untuk melakukan autentikasi ke Transcoder API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


using Google.Cloud.Video.Transcoder.V1;

public class DeleteJobTemplateSample
{
    public void DeleteJobTemplate(string projectId, string location, string templateId)
    {
        // Create the client.
        TranscoderServiceClient client = TranscoderServiceClient.Create();

        // Build the job template name.
        JobTemplateName name = JobTemplateName.FromProjectLocationJobTemplate(projectId, location, templateId);

        // Call the API.
        client.DeleteJobTemplate(name);
    }
}

Go

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Go di Panduan memulai Transcoder API menggunakan library klien. Untuk informasi selengkapnya, lihat Dokumentasi referensi API Go Transcoder API.

Untuk melakukan autentikasi ke Transcoder API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import (
	"context"
	"fmt"
	"io"

	transcoder "cloud.google.com/go/video/transcoder/apiv1"
	"cloud.google.com/go/video/transcoder/apiv1/transcoderpb"
)

// deleteJobTemplate deletes a previously-created template for a job. See
// https://cloud.google.com/transcoder/docs/how-to/job-templates#delete_job_template
// for more information.
func deleteJobTemplate(w io.Writer, projectID string, location string, templateID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// templateID := "my-job-template"
	ctx := context.Background()
	client, err := transcoder.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer client.Close()

	req := &transcoderpb.DeleteJobTemplateRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/jobTemplates/%s", projectID, location, templateID),
	}

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

	fmt.Fprintf(w, "Deleted job template")
	return nil
}

Java

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Java di Panduan memulai Transcoder API menggunakan library klien. Untuk informasi selengkapnya, lihat Dokumentasi referensi API Java Transcoder API.

Untuk melakukan autentikasi ke Transcoder API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


import com.google.cloud.video.transcoder.v1.DeleteJobTemplateRequest;
import com.google.cloud.video.transcoder.v1.JobTemplateName;
import com.google.cloud.video.transcoder.v1.TranscoderServiceClient;
import java.io.IOException;

public class DeleteJobTemplate {

  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 templateId = "my-job-template";

    deleteJobTemplate(projectId, location, templateId);
  }

  // Deletes a job template.
  public static void deleteJobTemplate(String projectId, String location, String templateId)
      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 (TranscoderServiceClient transcoderServiceClient = TranscoderServiceClient.create()) {
      JobTemplateName jobTemplateName =
          JobTemplateName.newBuilder()
              .setProject(projectId)
              .setLocation(location)
              .setJobTemplate(templateId)
              .build();
      DeleteJobTemplateRequest deleteJobTemplateRequest =
          DeleteJobTemplateRequest.newBuilder().setName(jobTemplateName.toString()).build();

      // Send the delete job template request and process the response.
      transcoderServiceClient.deleteJobTemplate(deleteJobTemplateRequest);
      System.out.println("Deleted job template");
    }
  }
}

Node.js

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Node.js di Panduan memulai Transcoder API menggunakan library klien. Untuk informasi selengkapnya, lihat Dokumentasi referensi API Node.js Transcoder API.

Untuk melakukan autentikasi ke Transcoder 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';
// templateId = 'my-job-template';

// Imports the Transcoder library
const {TranscoderServiceClient} =
  require('@google-cloud/video-transcoder').v1;

// Instantiates a client
const transcoderServiceClient = new TranscoderServiceClient();

async function deleteJobTemplate() {
  // Construct request
  const request = {
    name: transcoderServiceClient.jobTemplatePath(
      projectId,
      location,
      templateId
    ),
  };
  await transcoderServiceClient.deleteJobTemplate(request);
  console.log('Deleted job template');
}

deleteJobTemplate();

PHP

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan PHP di Panduan memulai Transcoder API menggunakan library klien. Untuk informasi selengkapnya, lihat Dokumentasi referensi API PHP Transcoder API.

Untuk melakukan autentikasi ke Transcoder API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient;
use Google\Cloud\Video\Transcoder\V1\DeleteJobTemplateRequest;

/**
 * Deletes a Transcoder job template.
 *
 * @param string $projectId The ID of your Google Cloud Platform project.
 * @param string $location The location of the job template.
 * @param string $templateId The user-defined template ID.
 */
function delete_job_template($projectId, $location, $templateId)
{
    // Instantiate a client.
    $transcoderServiceClient = new TranscoderServiceClient();

    $formattedName = $transcoderServiceClient->jobTemplateName($projectId, $location, $templateId);
    $request = (new DeleteJobTemplateRequest())
        ->setName($formattedName);
    $transcoderServiceClient->deleteJobTemplate($request);

    print('Deleted job template' . PHP_EOL);
}

Python

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Python di Panduan memulai Transcoder API menggunakan library klien. Untuk informasi selengkapnya, lihat Dokumentasi referensi API Python Transcoder API.

Untuk melakukan autentikasi ke Transcoder API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


import argparse

from google.cloud.video.transcoder_v1.services.transcoder_service import (
    TranscoderServiceClient,
)

def delete_job_template(
    project_id: str,
    location: str,
    template_id: str,
) -> None:
    """Deletes a job template.

    Args:
        project_id: The GCP project ID.
        location: The location of the template.
        template_id: The user-defined template ID."""

    client = TranscoderServiceClient()

    name = f"projects/{project_id}/locations/{location}/jobTemplates/{template_id}"
    response = client.delete_job_template(name=name)
    print("Deleted job template")
    return response

Ruby

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Ruby di Panduan memulai Transcoder API menggunakan library klien. Untuk informasi selengkapnya, lihat Dokumentasi referensi API Ruby Transcoder API.

Untuk melakukan autentikasi ke Transcoder API, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

# project_id = "YOUR-GOOGLE-CLOUD-PROJECT"  # (e.g. "my-project")
# location    = "YOUR-JOB-TEMPLATE-LOCATION"  # (e.g. "us-central1")
# template_id = "YOUR-JOB-TEMPLATE"  # (e.g. "my-job-template")

# Require the Transcoder client library.
require "google/cloud/video/transcoder"

# Create a Transcoder client.
client = Google::Cloud::Video::Transcoder.transcoder_service

# Build the resource name of the job template.
name = client.job_template_path project: project_id, location: location, job_template: template_id

# Delete the job template.
client.delete_job_template name: name

# Print a success message.
puts "Deleted job template"

Langkah selanjutnya

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