Obtenir une clé CDN

Obtenez des informations sur une ressource de clé CDN d'assembleur vidéo.

En savoir plus

Pour obtenir une documentation détaillée incluant cet exemple de code, consultez les articles suivants :

Exemple de code

C#

Avant d'essayer cet exemple, suivez les instructions de configuration pour C# du guide de démarrage rapide de l'API Video Stitcher à l'aide des bibliothèques clientes. Pour en savoir plus, consultez la documentation de référence de l'API C# de l'outil de montage vidéo.

Pour vous authentifier auprès de l'API Video Stitcher, configurez le service Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.


using Google.Cloud.Video.Stitcher.V1;

public class GetCdnKeySample
{
    public CdnKey GetCdnKey(
        string projectId, string location, string cdnKeyId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        GetCdnKeyRequest request = new GetCdnKeyRequest
        {
            CdnKeyName = CdnKeyName.FromProjectLocationCdnKey(projectId, location, cdnKeyId)
        };

        // Call the API.
        CdnKey response = client.GetCdnKey(request);

        // Return the result.
        return response;
    }
}

Go

Avant d'essayer cet exemple, suivez les instructions de configuration pour Go du guide de démarrage rapide de l'API Video Stitcher à l'aide des bibliothèques clientes. Pour en savoir plus, consultez la documentation de référence de l'API Go de l'outil de montage vidéo.

Pour vous authentifier auprès de l'API Video Stitcher, configurez le service Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

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

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

// getCDNKey gets a CDN key by ID.
func getCDNKey(w io.Writer, projectID, keyID string) error {
	// projectID := "my-project-id"
	// keyID := "my-cdn-key"
	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.GetCdnKeyRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/cdnKeys/%s", projectID, location, keyID),
	}
	// Gets the CDN key.
	response, err := client.GetCdnKey(ctx, req)
	if err != nil {
		return fmt.Errorf("client.GetCdnKey: %w", err)
	}
	b, err := json.MarshalIndent(response, "", " ")
	if err != nil {
		return fmt.Errorf("json.MarshalIndent: %w", err)
	}

	fmt.Fprintf(w, "CDN key:\n%s", string(b))
	return nil
}

Java

Avant d'essayer cet exemple, suivez les instructions de configuration pour Java du guide de démarrage rapide de l'API Video Stitcher à l'aide des bibliothèques clientes. Pour en savoir plus, consultez la documentation de référence de l'API Java de l'outil de montage vidéo.

Pour vous authentifier auprès de l'API Video Stitcher, configurez le service Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.


import com.google.cloud.video.stitcher.v1.CdnKey;
import com.google.cloud.video.stitcher.v1.CdnKeyName;
import com.google.cloud.video.stitcher.v1.GetCdnKeyRequest;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import java.io.IOException;

public class GetCdnKey {

  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 cdnKeyId = "my-cdn-key-id";

    getCdnKey(projectId, location, cdnKeyId);
  }

  // Gets a CDN key.
  public static CdnKey getCdnKey(String projectId, String location, String cdnKeyId)
      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()) {
      GetCdnKeyRequest getCdnKeyRequest =
          GetCdnKeyRequest.newBuilder()
              .setName(CdnKeyName.of(projectId, location, cdnKeyId).toString())
              .build();

      CdnKey response = videoStitcherServiceClient.getCdnKey(getCdnKeyRequest);
      System.out.println("CDN key: " + response.getName());
      return response;
    }
  }
}

Node.js

Avant d'essayer cet exemple, suivez les instructions de configuration pour Node.js du guide de démarrage rapide de l'API Video Stitcher à l'aide des bibliothèques clientes. Pour en savoir plus, consultez la documentation de référence de l'API Node.js de l'outil de montage vidéo.

Pour vous authentifier auprès de l'API Video Stitcher, configurez le service Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

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

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

async function getCdnKey() {
  // Construct request
  const request = {
    name: stitcherClient.cdnKeyPath(projectId, location, cdnKeyId),
  };
  const [cdnKey] = await stitcherClient.getCdnKey(request);
  console.log(`CDN key: ${cdnKey.name}`);
}

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

PHP

Avant d'essayer cet exemple, suivez les instructions de configuration pour PHP du guide de démarrage rapide de l'API Video Stitcher à l'aide des bibliothèques clientes. Pour en savoir plus, consultez la documentation de référence de l'API PHP de l'outil de montage vidéo.

Pour vous authentifier auprès de l'API Video Stitcher, configurez le service Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

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

/**
 * Gets a CDN key.
 *
 * @param string $callingProjectId     The project ID to run the API call under
 * @param string $location             The location of the CDN key
 * @param string $cdnKeyId             The ID of the CDN key
 */
function get_cdn_key(
    string $callingProjectId,
    string $location,
    string $cdnKeyId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->cdnKeyName($callingProjectId, $location, $cdnKeyId);
    $request = (new GetCdnKeyRequest())
        ->setName($formattedName);
    $key = $stitcherClient->getCdnKey($request);

    // Print results
    printf('CDN key: %s' . PHP_EOL, $key->getName());
}

Python

Avant d'essayer cet exemple, suivez les instructions de configuration pour Python du guide de démarrage rapide de l'API Video Stitcher à l'aide des bibliothèques clientes. Pour en savoir plus, consultez la documentation de référence de l'API Python de l'outil de montage vidéo.

Pour vous authentifier auprès de l'API Video Stitcher, configurez le service Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.


import argparse

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


def get_cdn_key(
    project_id: str, location: str, cdn_key_id: str
) -> stitcher_v1.types.CdnKey:
    """Gets a CDN key.
    Args:
        project_id: The GCP project ID.
        location: The location of the CDN key.
        cdn_key_id: The user-defined CDN key ID.

    Returns:
        The CDN key resource.
    """

    client = VideoStitcherServiceClient()

    name = f"projects/{project_id}/locations/{location}/cdnKeys/{cdn_key_id}"
    response = client.get_cdn_key(name=name)
    print(f"CDN key: {response.name}")
    return response

Ruby

Avant d'essayer cet exemple, suivez les instructions de configuration pour Ruby du guide de démarrage rapide de l'API Video Stitcher à l'aide des bibliothèques clientes. Pour en savoir plus, consultez la documentation de référence de l'API Ruby de l'outil de montage vidéo.

Pour vous authentifier auprès de l'API Video Stitcher, configurez le service Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

require "google/cloud/video/stitcher"

##
# Get a CDN key
#
# @param project_id [String] Your Google Cloud project (e.g. `my-project`)
# @param location [String] The location (e.g. `us-central1`)
# @param cdn_key_id [String] Your CDN key name (e.g. `my-cdn-key`)
#
def get_cdn_key project_id:, location:, cdn_key_id:
  # Create a Video Stitcher client.
  client = Google::Cloud::Video::Stitcher.video_stitcher_service

  # Build the resource name of the CDN key.
  name = client.cdn_key_path project: project_id, location: location,
                             cdn_key: cdn_key_id

  # Get the CDN key.
  cdn_key = client.get_cdn_key name: name

  # Print the CDN key name.
  puts "CDN key: #{cdn_key.name}"
end

Étape suivante

Pour rechercher et filtrer des exemples de code pour d'autres Google Cloud produits, consultez l'explorateur d'exemplesGoogle Cloud .