获取作业

获取特定转码作业的详细信息。

深入探索

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

代码示例

C#

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

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


using Google.Cloud.Video.Transcoder.V1;

public class GetJobSample
{
    public Job GetJob(string projectId, string location, string jobId)
    {
        // Create the client.
        TranscoderServiceClient client = TranscoderServiceClient.Create();

        // Build the job name.
        JobName jobName = JobName.FromProjectLocationJob(projectId, location, jobId);

        // Call the API.
        Job job = client.GetJob(jobName);

        // Return the result.
        return job;
    }
}

Go

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

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

import (
	"context"
	"fmt"
	"io"

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

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

	req := &transcoderpb.GetJobRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/jobs/%s", projectID, location, jobID),
	}

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

	fmt.Fprintf(w, "Job: %v", response)
	return nil
}

Java

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

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


import com.google.cloud.video.transcoder.v1.GetJobRequest;
import com.google.cloud.video.transcoder.v1.Job;
import com.google.cloud.video.transcoder.v1.JobName;
import com.google.cloud.video.transcoder.v1.TranscoderServiceClient;
import java.io.IOException;

public class GetJob {

  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 jobId = "my-job-id";

    getJob(projectId, location, jobId);
  }

  // Gets a job.
  public static void getJob(String projectId, String location, String jobId) 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()) {
      JobName jobName =
          JobName.newBuilder().setProject(projectId).setLocation(location).setJob(jobId).build();
      GetJobRequest getJobRequest = GetJobRequest.newBuilder().setName(jobName.toString()).build();

      // Send the get job request and process the response.
      Job job = transcoderServiceClient.getJob(getJobRequest);
      System.out.println("Job: " + job.getName());
    }
  }
}

Node.js

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

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

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

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

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

async function getJob() {
  // Construct request
  const request = {
    name: transcoderServiceClient.jobPath(projectId, location, jobId),
  };
  const [response] = await transcoderServiceClient.getJob(request);
  console.log(`Job: ${response.name}`);
}

getJob();

PHP

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

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

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

/**
 * Gets a Transcoder job.
 *
 * @param string $projectId The ID of your Google Cloud Platform project.
 * @param string $location The location of the job.
 * @param string $jobId The job ID.
 */
function get_job($projectId, $location, $jobId)
{
    // Instantiate a client.
    $transcoderServiceClient = new TranscoderServiceClient();

    $formattedName = $transcoderServiceClient->jobName($projectId, $location, $jobId);
    $request = (new GetJobRequest())
        ->setName($formattedName);
    $job = $transcoderServiceClient->getJob($request);

    // Print job name.
    printf('Job: %s' . PHP_EOL, $job->getName());
}

Python

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

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


import argparse

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

def get_job(
    project_id: str,
    location: str,
    job_id: str,
) -> transcoder_v1.types.resources.Job:
    """Gets a job.

    Args:
        project_id: The GCP project ID.
        location: The location this job is in.
        job_id: The job ID.

    Returns:
        The job resource.
    """

    client = TranscoderServiceClient()

    name = f"projects/{project_id}/locations/{location}/jobs/{job_id}"
    response = client.get_job(name=name)
    print(f"Job: {response.name}")
    return response

Ruby

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

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

# project_id = "YOUR-GOOGLE-CLOUD-PROJECT"  # (e.g. "my-project")
# location   = "YOUR-JOB-LOCATION"  # (e.g. "us-central1")
# job_id     = "YOUR-JOB-ID"  # (e.g. "c82c295b-3f5a-47df-8562-938a89d40fd0")

# 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.
name = client.job_path project: project_id, location: location, job: job_id

# Get the job.
job = client.get_job name: name

# Print the job name.
puts "Job: #{job.name}"

后续步骤

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