Jobs auflisten

Listet alle Transcodierungsjobs für einen bestimmten Standort auf.

Weitere Informationen

Eine ausführliche Dokumentation, die dieses Codebeispiel enthält, finden Sie hier:

Codebeispiel

C#

Bevor Sie dieses Beispiel anwenden, folgen Sie den Schritten zur Einrichtung von C# in der Transcoder API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Referenzdokumentation zur Transcoder API für C#.

Richten Sie zur Authentifizierung bei der Transcoder API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.


using Google.Cloud.Video.Transcoder.V1;
using Google.Api.Gax.ResourceNames;
using Google.Api.Gax;
using System.Linq;
using System.Collections.Generic;

public class ListJobsSample
{
    public IList<Job> ListJobs(string projectId, string location)
    {
        // Create the client.
        TranscoderServiceClient client = TranscoderServiceClient.Create();

        // Build the parent location name.
        LocationName parentLocation = new LocationName(projectId, location);

        // Call the API.
        PagedEnumerable<ListJobsResponse, Job> response = client.ListJobs(parentLocation);

        // The returned sequence will lazily perform RPCs as it's being iterated over.
        return response.ToList();
    }
}

Go

Bevor Sie dieses Beispiel anwenden, folgen Sie den Schritten zur Einrichtung von Go in der Transcoder API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Referenzdokumentation zur Transcoder API für Go.

Richten Sie zur Authentifizierung bei der Transcoder API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.


import (
	"context"
	"fmt"
	"io"

	transcoder "cloud.google.com/go/video/transcoder/apiv1"
	transcoderpb "cloud.google.com/go/video/transcoder/apiv1/transcoderpb"
	"google.golang.org/api/iterator"
)

// listJobs lists transcoding jobs in the specified location.
func listJobs(ctx context.Context, w io.Writer, projectID string, locationID string) error {
	parent := fmt.Sprintf("projects/%s/locations/%s", projectID, locationID)

	client, err := transcoder.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient failed: %w", err)
	}
	defer client.Close()

	req := &transcoderpb.ListJobsRequest{
		Parent: parent,
	}

	it := client.ListJobs(ctx, req)
	fmt.Fprintln(w, "Jobs:")
	for {
		job, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("ListJobs: %w", err)
		}
		fmt.Fprintf(w, "%s\n", job.GetName())
	}

	return nil
}

Java

Bevor Sie dieses Beispiel anwenden, folgen Sie den Schritten zur Einrichtung von Java in der Transcoder API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Referenzdokumentation zur Transcoder API für Java.

Richten Sie zur Authentifizierung bei der Transcoder API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.


import com.google.cloud.video.transcoder.v1.Job;
import com.google.cloud.video.transcoder.v1.ListJobsRequest;
import com.google.cloud.video.transcoder.v1.LocationName;
import com.google.cloud.video.transcoder.v1.TranscoderServiceClient;
import java.io.IOException;

public class ListJobs {

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

    listJobs(projectId, location);
  }

  // Lists the jobs for a given location.
  public static void listJobs(String projectId, String location) 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()) {

      ListJobsRequest listJobsRequest =
          ListJobsRequest.newBuilder()
              .setParent(LocationName.of(projectId, location).toString())
              .build();

      // Send the list jobs request and process the response.
      TranscoderServiceClient.ListJobsPagedResponse response =
          transcoderServiceClient.listJobs(listJobsRequest);
      System.out.println("Jobs:");

      for (Job job : response.iterateAll()) {
        System.out.println(job.getName());
      }
    }
  }
}

Node.js

Bevor Sie dieses Beispiel anwenden, folgen Sie den Schritten zur Einrichtung von Node.js in der Transcoder API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Referenzdokumentation zur Transcoder API für Node.js.

Richten Sie zur Authentifizierung bei der Transcoder API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

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

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

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

async function listJobs() {
  const iterable = await transcoderServiceClient.listJobsAsync({
    parent: transcoderServiceClient.locationPath(projectId, location),
  });
  console.info('Jobs:');
  for await (const response of iterable) {
    console.log(response.name);
  }
}

listJobs();

PHP

Bevor Sie dieses Beispiel anwenden, folgen Sie den Schritten zur Einrichtung von PHP in der Transcoder API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Referenzdokumentation zur Transcoder API für PHP.

Richten Sie zur Authentifizierung bei der Transcoder API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

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

/**
 * Lists all Transcoder jobs in a location.
 *
 * @param string $projectId The ID of your Google Cloud Platform project.
 * @param string $location The location of the jobs.
 */
function list_jobs($projectId, $location)
{
    // Instantiate a client.
    $transcoderServiceClient = new TranscoderServiceClient();

    $formattedParent = $transcoderServiceClient->locationName($projectId, $location);
    $request = (new ListJobsRequest())
        ->setParent($formattedParent);
    $response = $transcoderServiceClient->listJobs($request);

    // Print job list.
    $jobs = $response->iterateAllElements();
    print('Jobs:' . PHP_EOL);
    foreach ($jobs as $job) {
        printf('%s' . PHP_EOL, $job->getName());
    }
}

Python

Bevor Sie dieses Beispiel anwenden, folgen Sie den Schritten zur Einrichtung von Python in der Transcoder API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Referenzdokumentation zur Transcoder API für Python.

Richten Sie zur Authentifizierung bei der Transcoder API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.


import argparse

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


def list_jobs(
    project_id: str,
    location: str,
) -> pagers.ListJobsPager:
    """Lists all jobs in a location.

    Args:
        project_id: The GCP project ID.
        location: The location of the jobs.

    Returns:
        An iterable object containing job resources.
    """

    client = TranscoderServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    response = client.list_jobs(parent=parent)
    print("Jobs:")
    for job in response.jobs:
        print({job.name})

    return response

Ruby

Bevor Sie dieses Beispiel anwenden, folgen Sie den Schritten zur Einrichtung von Ruby in der Transcoder API-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Referenzdokumentation zur Transcoder API für Ruby.

Richten Sie zur Authentifizierung bei der Transcoder API Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

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

# 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 parent.
parent = client.location_path project: project_id, location: location

# Get the list of jobs.
response = client.list_jobs parent: parent

puts "Jobs:"
# Print out all jobs.
response.each do |job|
  puts job.name
end

Nächste Schritte

Wenn Sie nach Codebeispielen für andere Produkte von Google Cloud suchen und filtern möchten, können Sie den Beispielbrowser fürGoogle Cloud verwenden.