Query video face fusion templates

Updated at:

This document provides sample code in common programming languages for querying video face fusion templates.

Note
  • For real-time assistance, start an online consultation.

  • If you have questions about API access or usage for the Alibaba Cloud Vision AI Platform, join our DingTalk group (ID: 23109592) to contact us.

Overview

For a functional overview and a description of the request parameters, see Query video face fusion templates.

SDK installation

For information about the SDK packages available for common programming languages, see SDK overview.

Configure environment variables

Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.

Important
  • An Alibaba Cloud account has full access to all API operations. We recommend that you use a RAM user for API calls or routine O&M. For more information, see Create a RAM user.

  • Do not save your AccessKey ID or AccessKey Secret in project code. Otherwise, the AccessKey pair may be leaked and the security of all resources in your account may be compromised.

  • Configure environment variables on Linux and macOS

    1. Open a terminal in IntelliJ IDEA.

    2. Run the following commands to configure the environment variables.

      Replace <access_key_id> with the AccessKey ID of your RAM user and <access_key_secret> with the AccessKey Secret of your RAM user. If you need to configure more permissions, see Control access permissions using a RAM policy.

      export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>
      export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
  • Configure environment variables on Windows

    Create a new environment variable file, add the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET, and set them to the AccessKey ID and AccessKey Secret that you have prepared. Then, restart the Windows operating system. The following example uses Windows 10.

    1. Open File Explorer, right-click This PC, and then select Properties.

    2. In the left-side navigation pane, click Advanced system settings.

    3. On the Advanced tab of the System Properties dialog box, click Environment Variables.

    4. In the Environment Variables dialog box, click New.

    5. In the New System Variable dialog box, add the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET, and set them to the AccessKey ID and AccessKey Secret that you have prepared.

    6. Restart the Windows operating system for the configurations to take effect.

Sample code

/*
Import the dependency package
<!-- https://mvnrepository.com/artifact/com.aliyun/videoenhan20200320 -->
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>videoenhan20200320</artifactId>
  <version>${aliyun.videoenhan.version}</version>
</dependency>
*/

import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaModel;
import com.aliyun.videoenhan20200320.models.QueryFaceVideoTemplateResponse;

public class QueryFaceVideoTemplate {
    public static com.aliyun.videoenhan20200320.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        /*
          Initialize the com.aliyun.teaopenapi.models.Config object, which stores your AccessKey ID, AccessKey Secret, endpoint, and other configuration details.
         */
         com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        // The regional endpoint.
        config.endpoint = "videoenhan.cn-shanghai.aliyuncs.com";
        return new com.aliyun.videoenhan20200320.Client(config);
    }

    public static void main(String[] args) throws Exception {
        // For more information on how to create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
        // If you use the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // This example reads the AccessKey ID and AccessKey Secret from environment variables. You must configure these variables before running the code.
        String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"); 
        com.aliyun.videoenhan20200320.Client client = QueryFaceVideoTemplate.createClient(accessKeyId, accessKeySecret);
        com.aliyun.videoenhan20200320.models.QueryFaceVideoTemplateRequest queryFaceVideoTemplateRequest = new com.aliyun.videoenhan20200320.models.QueryFaceVideoTemplateRequest()
                .setTemplateId("26a42352-2991-4713-85dd-6d8f7cd59b58");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            QueryFaceVideoTemplateResponse queryFaceVideoTemplateResponse = client.queryFaceVideoTemplateWithOptions(queryFaceVideoTemplateRequest, runtime);
            // Get the complete response.
            System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(queryFaceVideoTemplateResponse)));
            // Get a specific field from the response.
            System.out.println(queryFaceVideoTemplateResponse.getBody());
        } catch (TeaException teaException) {
            // Get the complete error message.
            System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
            // Get a specific field from the error.
            System.out.println(teaException.getCode());
        }
    }
}
# -*- coding: utf-8 -*-
# Install the dependency package
# pip install alibabacloud_videoenhan20200320

import os
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions
from alibabacloud_videoenhan20200320.client import Client
from alibabacloud_videoenhan20200320.models import QueryFaceVideoTemplateRequest

config = Config(
  # For more information on how to create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  # If you use the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  # This example reads the AccessKey ID and AccessKey Secret from environment variables. You must configure these variables before running the code.
  access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
  access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
  # The regional endpoint.
  endpoint='videoenhan.cn-shanghai.aliyuncs.com',
  # The ID of the region that corresponds to your endpoint.
  region_id='cn-shanghai'
)
query_face_video_template_request = QueryFaceVideoTemplateRequest(
    template_id='26a42352-2991-4713-85dd-6d8f7cd59b58'
)
runtime = RuntimeOptions()
try:
  # Initialize the client.
  client = Client(config)
  response = client.query_face_video_template_with_options(query_face_video_template_request, runtime)
  # Get the complete response.
  print(response.body)
except Exception as error:
  # Get the complete error message.
  print(error)
  # Get a specific field from the error.
  print(error.code)
<?php

// Install the dependency package
// composer require alibabacloud/videoenhan-20200320

use AlibabaCloud\SDK\Videoenhan\V20200320\Videoenhan;
use \Exception;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Videoenhan\V20200320\Models\QueryFaceVideoTemplateRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class QueryFaceVideoTemplate {

    /**
     * Initialize the client with an AccessKey ID and AccessKey Secret.
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Videoenhan Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        // Initialize the Darabonba\OpenApi\Models\Config object, which stores your AccessKey ID, AccessKey Secret, endpoint, and other configuration details.
        $config = new Config([
            "accessKeyId" => $accessKeyId,
            "accessKeySecret" => $accessKeySecret
        ]);
        // The regional endpoint.
        $config->endpoint = "videoenhan.cn-shanghai.aliyuncs.com";
        return new Videoenhan($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        // For more information on how to create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
        // If you use the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
        // This example reads the AccessKey ID and AccessKey Secret from environment variables. You must configure these variables before running the code.
        $accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');      
        $accessKeySecret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
        $client = self::createClient($accessKeyId, $accessKeySecret);
        $queryFaceVideoTemplateRequest = new QueryFaceVideoTemplateRequest([
            "templateId" => "26a42352-2991-4713-85dd-6d8f7cd59b58"
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            $resp = $client->queryFaceVideoTemplateWithOptions($queryFaceVideoTemplateRequest, $runtime);
            # Get the complete response.
            echo Utils::toJSONString($resp->body);
        } catch (Exception $exception) {
            # Get the complete error message.
            echo Utils::toJSONString($exception);
            # Get a specific field from the error.
            echo $exception->getCode();
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
// Do not modify the $argv parameter. It is a reserved array for input arguments.
QueryFaceVideoTemplate::main(array_slice($argv, 1));
// Install the dependency package
// npm install @alicloud/videoenhan20200320
const VideoenhanClient = require('@alicloud/videoenhan20200320');
const OpenapiClient = require('@alicloud/openapi-client');
const TeaUtil = require('@alicloud/tea-util');

let config = new OpenapiClient.Config({
  // For more information on how to create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  // If you use the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // This example reads the AccessKey ID and AccessKey Secret from environment variables. You must configure these variables before running the code.
  accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,   
  accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// The regional endpoint.
config.endpoint = `videoenhan.cn-shanghai.aliyuncs.com`;
const client = new VideoenhanClient.default(config);
let queryFaceVideoTemplateRequest = new VideoenhanClient.QueryFaceVideoTemplateRequest({
  templateId: "26a42352-2991-4713-85dd-6d8f7cd59b58",
});
let runtime = new TeaUtil.RuntimeOptions({});
client.queryFaceVideoTemplateWithOptions(queryFaceVideoTemplateRequest, runtime)
  .then(function (queryFaceVideoTemplateResponse) {
    // Get the complete response.
    console.log(queryFaceVideoTemplateResponse);
    // Get a specific field from the response.
    console.log(queryFaceVideoTemplateResponse.body.data);
  }, function (error) {
    // Get the complete error message.
    console.log(error);
    // Get a specific field from the error.
    console.log(error.data.Code);
  })
/**
This code depends on github.com/alibabacloud-go/videoenhan-20200320/v3
Run the `go mod tidy` command to install dependencies.
*/

package main

import (
	"fmt"
	"os"
	openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
	util "github.com/alibabacloud-go/tea-utils/v2/service"
	"github.com/alibabacloud-go/tea/tea"
	videoenhan20200320 "github.com/alibabacloud-go/videoenhan-20200320/v3/client"
)

func main() {  
  // For more information on how to create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
  // If you use the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
  // This example reads the AccessKey ID and AccessKey Secret from environment variables. You must configure these variables before running the code.
  accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")  
  accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
  // Initialize the configuration object &openapi.Config. This object stores your AccessKey ID, AccessKey Secret, endpoint, and other configuration details.
	config := &openapi.Config{
		AccessKeyId: tea.String(accessKeyId),
		AccessKeySecret: tea.String(accessKeySecret),
	}
	// The regional endpoint.
	config.Endpoint = tea.String("videoenhan.cn-shanghai.aliyuncs.com")
	client, err := videoenhan20200320.NewClient(config)
	if err != nil {
		panic(err)
	}
	queryFaceVideoTemplateRequest := &videoenhan20200320.QueryFaceVideoTemplateRequest{
		TemplateId: tea.String("26a42352-2991-4713-85dd-6d8f7cd59b58"),
	}
	runtime := &util.RuntimeOptions{}
	queryFaceVideoTemplateResponse, err := client.QueryFaceVideoTemplateWithOptions(queryFaceVideoTemplateRequest, runtime)
	if err != nil {
		// Get the complete error message.
		fmt.Println(err.Error())
	} else {
		// Get the complete response.
		fmt.Println(queryFaceVideoTemplateResponse)
	}
}
// Install the dependency package
// dotnet add package AlibabaCloud.SDK.Videoenhan20200320
using System;
using System.Collections.Generic;
using AlibabaCloud.SDK.Videoenhan20200320.Models;
using Tea;

namespace AlibabaCloud.SDK.Sample
{
    public class Sample
    {
        /**
            * Initialize the client with an AccessKey ID and AccessKey Secret.
            * @param accessKeyId
            * @param accessKeySecret
            * @return Client
            * @throws Exception
        */
        public static AlibabaCloud.SDK.Videoenhan20200320.Client CreateClient(string accessKeyId, string accessKeySecret)
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
            {
                AccessKeyId = accessKeyId,
                AccessKeySecret = accessKeySecret,
            };
            // The regional endpoint.
            config.Endpoint = "videoenhan.cn-shanghai.aliyuncs.com";
            return new AlibabaCloud.SDK.Videoenhan20200320.Client(config);
        }
        public static void Main(string[] args)
        {
            // For more information on how to create an AccessKey ID and AccessKey Secret, see https://help.aliyun.com/document_detail/175144.html.
            // If you use the AccessKey of a RAM user, you must grant the AliyunVIAPIFullAccess permission to the RAM user. For more information, see https://help.aliyun.com/document_detail/145025.html.
            // This example reads the AccessKey ID and AccessKey Secret from environment variables. You must configure these variables before running the code.
            AlibabaCloud.SDK.Videoenhan20200320.Client client = CreateClient(System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
            AlibabaCloud.SDK.Videoenhan20200320.Models.QueryFaceVideoTemplateRequest queryFaceVideoTemplateRequest = new AlibabaCloud.SDK.Videoenhan20200320.Models.QueryFaceVideoTemplateRequest
            {
                TemplateId = "26a42352-2991-4713-85dd-6d8f7cd59b58",
            };
            AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
            try
            {
                AlibabaCloud.SDK.Videoenhan20200320.Models.QueryFaceVideoTemplateResponse queryFaceVideoTemplateResponse = client.QueryFaceVideoTemplateWithOptions(queryFaceVideoTemplateRequest, runtime);
                // Get the complete response.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(queryFaceVideoTemplateResponse.Body));
                // Get a specific field from the response.
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(queryFaceVideoTemplateResponse.Body.Data));
            }
            catch (TeaException error)
            {
                // Print the exception details.
                AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
            }
            catch (Exception _error)
            {
                TeaException error = new TeaException(new Dictionary<string, object>
                {
                    { "message", _error.Message }
                });
                // Print the exception details.
                Console.WriteLine(error.Message);
            }
        }
    }
}