Smart Tag Service
This topic provides sample code that shows how to use the PHP software development kit (SDK) V2.0 to implement smart tagging.
Prerequisites
Before you start, you must initialize the client. For more information, see Initialization.
Submit a smart tagging job
You can call the SubmitSmarttagJob operation to submit a smart tagging job. For more information, see Submit a smart tagging job. The following sample code is provided:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\SubmitSmarttagJobRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Sample {
/**
* Use an AccessKey pair to initialize the client.
* @return Mts Client
*/
public static function createClient(){
$config = new Config([
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
"accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
"accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);
$config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
return new Mts($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
$client = self::createClient();
$submitSmarttagJobRequest = new SubmitSmarttagJobRequest([
// The ID of the MPS queue.
"pipelineId" => "2",
// The title of the video.
"title" => "example-title-****",
// The description of the video content.
"content" => "example content ****",
// The additional request parameters.
"params" => "false",
// The callback path.
"notifyUrl" => "https://example.com/endpoint/aliyun/ai?id=76401125000***",
// The pass-through information that is returned in the callback.
"userData" => "{\"key\":\"value\"}",
// The URL of the video or image file that you want to analyze.
"input" => "oss://mybucket-****/example-****.mp4",
// The template ID. This ID specifies the analysis algorithm.
"templateId" => "39f8e0bc005e4f309379701645f4****",
// The priority of the job in the MPS queue.
"priority" => "5"
]);
$runtime = new RuntimeOptions([]);
try {
// If you copy this code, print the API return value.
$client->submitSmarttagJobWithOptions($submitSmarttagJobRequest, $runtime);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
// The following code is for demonstration only. In a production environment, handle exceptions with care and do not ignore them.
// Error message
var_dump($error->message);
// Diagnostic address
var_dump($error->data["Recommend"]);
Utils::assertAsString($error->message);
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));Query a smart tagging job
You can call the QuerySmarttagJob operation to query a smart tagging job. For more information, see Query a smart tagging job. The following sample code is provided:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\QuerySmarttagJobRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Sample {
/**
* Use an AccessKey pair to initialize the client.
* @return Mts Client
*/
public static function createClient(){
$config = new Config([
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
"accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
"accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);
$config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
return new Mts($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
$client = self::createClient();
$querySmarttagJobRequest = new QuerySmarttagJobRequest([
// The ID of the smart tagging job that you want to query.
"jobId" => "39f8e0bc005e4f309379701645f4****",
// The additional request parameters.
"params" => "{\"labelResultType\":\"auto\"}"
]);
$runtime = new RuntimeOptions([]);
try {
// If you copy this code, print the API return value.
$client->querySmarttagJobWithOptions($querySmarttagJobRequest, $runtime);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
// The following code is for demonstration only. In a production environment, handle exceptions with care and do not ignore them.
// Error message
var_dump($error->message);
// Diagnostic address
var_dump($error->data["Recommend"]);
Utils::assertAsString($error->message);
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));
Add template
You can call the AddSmarttagTemplate operation to add a smart tagging template. For more information, see Add a template. The following sample code is provided:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\AddSmarttagTemplateRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Sample {
/**
* Use an AccessKey pair to initialize the client.
* @return Mts Client
*/
public static function createClient(){
$config = new Config([
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
"accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
"accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);
$config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
return new Mts($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
$client = self::createClient();
$addSmarttagTemplateRequest = new AddSmarttagTemplateRequest([
// The custom template name.
"templateName" => "template-example-****",
// The industry of the file to be analyzed.
"industry" => "common",
// The scenario in which the file is used.
"scene" => "search",
// The analysis type.
"analyseTypes" => "ocr",
// The IDs of the face libraries used for recognition.
"faceCategoryIds" => "celebrity",
// The parameters of the face algorithm.
"faceCustomParamsConfig" => "{ \"faceDetThreshold\":0.999, \"faceRegThreshold\":0.9 }",
// The IDs of the object libraries used for recognition.
"objectGroupIds" => "general,item,weapon,animal",
// The IDs of the landmark libraries used for recognition.
"landmarkGroupIds" => "common",
// Specifies whether to set the template as the default template. If you set this parameter to true, this template is used for transcoding when no transcoding template is specified.
"isDefault" => true,
// The tagging type.
"labelType" => "hmi",
// The version of the smart tagging feature.
"labelVersion" => "1.0",
// In smart tagging 2.0 and 2.0-custom modes, this parameter specifies the scope of the knowledge graph fields that are returned in the tagging results.
"knowledgeConfig" => "{ \"movie\":\"name,alias,chnl,genre\", \"music\":\"songName,artistName\", \"person\":\"name,gender\" }",
// The keyword tag configuration.
"keywordConfig" => "\"type\": \"name,location,organization,other\" }"
]);
$runtime = new RuntimeOptions([]);
try {
// If you copy this code, print the API return value.
$client->addSmarttagTemplateWithOptions($addSmarttagTemplateRequest, $runtime);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
// The following code is for demonstration only. In a production environment, handle exceptions with care and do not ignore them.
// Error message
var_dump($error->message);
// Diagnostic address
var_dump($error->data["Recommend"]);
Utils::assertAsString($error->message);
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));
Query templates
You can call the QuerySmarttagTemplateList operation to query smart tagging templates. For more information, see Query templates. The following sample code is provided:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\QuerySmarttagTemplateListRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Sample {
/**
* Use an AccessKey pair to initialize the client.
* @return Mts Client
*/
public static function createClient(){
$config = new Config([
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
"accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
"accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);
$config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
return new Mts($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
$client = self::createClient();
$querySmarttagTemplateListRequest = new QuerySmarttagTemplateListRequest([
// The template ID.
"templateId" => "05de22f255284c7a8d2aab535dde****"
]);
$runtime = new RuntimeOptions([]);
try {
// If you copy this code, print the API return value.
$client->querySmarttagTemplateListWithOptions($querySmarttagTemplateListRequest, $runtime);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
// The following code is for demonstration only. In a production environment, handle exceptions with care and do not ignore them.
// Error message
var_dump($error->message);
// Diagnostic address
var_dump($error->data["Recommend"]);
Utils::assertAsString($error->message);
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));
Update template
You can call the UpdateSmarttagTemplate operation to update a smart tagging template. For more information, see Update a template. The following sample code is provided:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\UpdateSmarttagTemplateRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Sample {
/**
* Use an AccessKey pair to initialize the client.
* @return Mts Client
*/
public static function createClient(){
$config = new Config([
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
"accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
"accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);
$config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
return new Mts($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
$client = self::createClient();
$updateSmarttagTemplateRequest = new UpdateSmarttagTemplateRequest([
// The template ID.
"templateId" => "05de22f255284c7a8d2aab535dde****",
// The custom template name.
"templateName" => "template-example-****",
// The industry of the file to be analyzed.
"industry" => "common",
// The scenario.
"scene" => "search",
// The analysis type.
"analyseTypes" => "ocr,asr",
// The IDs of the face libraries used for recognition.
"faceCategoryIds" => "celebrity",
// The parameters of the face algorithm.
"faceCustomParamsConfig" => "{ \"faceDetThreshold\":0.999, \"faceRegThreshold\":0.9 }",
// The IDs of the object libraries used for recognition.
"objectGroupIds" => "general,item,weapon,animal",
// The IDs of the landmark libraries used for recognition.
"landmarkGroupIds" => "common",
// Specifies whether this is the default template.
"isDefault" => true,
// The tagging type.
"labelType" => "hmi",
// The version of the smart tagging feature.
"labelVersion" => "1.0",
// In smart tagging 2.0 and 2.0-custom modes, this parameter specifies the scope of the knowledge graph fields that are returned in the tagging results.
"knowledgeConfig" => "{ \"movie\":\"name,alias,chnl,genre\", \"music\":\"songName,artistName\", \"person\":\"name,gender\" }",
// The keyword tag configuration.
"keywordConfig" => "{ \"type\": \"name,location,organization,other\" }"
]);
$runtime = new RuntimeOptions([]);
try {
// If you copy this code, print the API return value.
$client->updateSmarttagTemplateWithOptions($updateSmarttagTemplateRequest, $runtime);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
// The following code is for demonstration only. In a production environment, handle exceptions with care and do not ignore them.
// Error message
var_dump($error->message);
// Diagnostic address
var_dump($error->data["Recommend"]);
Utils::assertAsString($error->message);
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));
Delete template
You can call the DeleteSmarttagTemplate operation to delete a smart tagging template. For more information, see Delete a template. The following sample code is provided:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\DeleteSmarttagTemplateRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Sample {
/**
* Use an AccessKey pair to initialize the client.
* @return Mts Client
*/
public static function createClient(){
$config = new Config([
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
"accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
"accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);
$config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
return new Mts($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
$client = self::createClient();
$deleteSmarttagTemplateRequest = new DeleteSmarttagTemplateRequest([
// The ID of the template that you want to delete.
"templateId" => "05de22f255284c7a8d2aab535dde****"
]);
$runtime = new RuntimeOptions([]);
try {
// If you copy this code, print the API return value.
$client->deleteSmarttagTemplateWithOptions($deleteSmarttagTemplateRequest, $runtime);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
// The following code is for demonstration only. In a production environment, handle exceptions with care and do not ignore them.
// Error message
var_dump($error->message);
// Diagnostic address
var_dump($error->data["Recommend"]);
Utils::assertAsString($error->message);
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));
Register a custom face
You can call the RegisterCustomFace operation to register a custom face. For more information, see Register a custom face. The following sample code is provided:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\RegisterCustomFaceRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Sample {
/**
* Use an AccessKey pair to initialize the client.
* @return Mts Client
*/
public static function createClient(){
$config = new Config([
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
"accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
"accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);
$config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
return new Mts($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
$client = self::createClient();
$registerCustomFaceRequest = new RegisterCustomFaceRequest([
// The ID of the person library.
"categoryId" => "CategoryId001-****",
// The ID of the person.
"personId" => "PersonId001-****",
// The public URL of the face image that you want to register.
"imageUrl" => "http://example-****.jpeg"
]);
$runtime = new RuntimeOptions([]);
try {
// If you copy this code, print the API return value.
$client->registerCustomFaceWithOptions($registerCustomFaceRequest, $runtime);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
// The following code is for demonstration only. In a production environment, handle exceptions with care and do not ignore them.
// Error message
var_dump($error->message);
// Diagnostic address
var_dump($error->data["Recommend"]);
Utils::assertAsString($error->message);
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));
Deregister a custom face
You can call the UnregisterCustomFace operation to unregister a custom face. For more information, see Unregister a custom face. The following sample code is provided:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\UnregisterCustomFaceRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Sample {
/**
* Use an AccessKey pair to initialize the client.
* @return Mts Client
*/
public static function createClient(){
$config = new Config([
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
"accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
"accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);
$config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
return new Mts($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
$client = self::createClient();
$unregisterCustomFaceRequest = new UnregisterCustomFaceRequest([
// The ID of the person library.
"categoryId" => "CategoryId001-****",
// The ID of the person.
"personId" => "PersonId001-****",
// The face ID.
"faceId" => "15****"
]);
$runtime = new RuntimeOptions([]);
try {
// If you copy this code, print the API return value.
$client->unregisterCustomFaceWithOptions($unregisterCustomFaceRequest, $runtime);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
// The following code is for demonstration only. In a production environment, handle exceptions with care and do not ignore them.
// Error message
var_dump($error->message);
// Diagnostic address
var_dump($error->data["Recommend"]);
Utils::assertAsString($error->message);
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));
Add a custom figure library or figure tag
You can call the TagCustomPerson operation to add a custom person library or person tag. For more information, see Add a custom person library or person tag. The following sample code is provided:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\TagCustomPersonRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Sample {
/**
* Use an AccessKey pair to initialize the client.
* @return Mts Client
*/
public static function createClient(){
$config = new Config([
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
"accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
"accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);
$config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
return new Mts($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
$client = self::createClient();
$tagCustomPersonRequest = new TagCustomPersonRequest([
// The ID of the person library.
"categoryId" => "CategoryId001-****",
// The name of the person library.
"categoryName" => "CategoryNametest-****",
// The description of the person library.
"categoryDescription" => "CategoryDescription001-****",
// The ID of the person.
"personId" => "PersonId001-****",
// The name of the person.
"personName" => "PersonNametest-****",
// The description of the person.
"personDescription" => "PersonDescriptiontest-****"
]);
$runtime = new RuntimeOptions([]);
try {
// If you copy this code, print the API return value.
$client->tagCustomPersonWithOptions($tagCustomPersonRequest, $runtime);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
// The following code is for demonstration only. In a production environment, handle exceptions with care and do not ignore them.
// Error message
var_dump($error->message);
// Diagnostic address
var_dump($error->data["Recommend"]);
Utils::assertAsString($error->message);
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));
List all persons and faces in a person library
You can call the ListCustomPersons operation to list all persons and faces in a person library. For more information, see List all persons and faces in a person library. The following sample code is provided:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\ListCustomPersonsRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Sample {
/**
* Use an AccessKey pair to initialize the client.
* @return Mts Client
*/
public static function createClient(){
$config = new Config([
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
"accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
"accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);
$config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
return new Mts($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
$client = self::createClient();
$listCustomPersonsRequest = new ListCustomPersonsRequest([
// The ID of the person library.
"categoryId" => "CategoryId-****",
// The ID of the person.
"personId" => "PersonId-****"
]);
$runtime = new RuntimeOptions([]);
try {
// If you copy this code, print the API return value.
$client->listCustomPersonsWithOptions($listCustomPersonsRequest, $runtime);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
// The following code is for demonstration only. In a production environment, handle exceptions with care and do not ignore them.
// Error message
var_dump($error->message);
// Diagnostic address
var_dump($error->data["Recommend"]);
Utils::assertAsString($error->message);
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));