本文介绍了如何使用.NET SDK,删除无用的个体人脸图片。

功能描述

删除人脸图片时,必须指定要删除的图片ID以及对应的个体ID信息。关于参数的详细说明,请参见删除人脸API文档

您需要使用内容安全的API接入地址,调用本SDK接口。关于API接入地址的信息,请参见接入地址(Endpoint)

前提条件

已安装.NET依赖。关于安装.NET依赖的具体操作,请参见安装.NET依赖
说明 请一定按照安装.NET依赖页面中的版本安装,否则会导致调用失败。

提交删除人脸任务

using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20180509;
using System.Collections.Generic;

namespace csharp_sdk_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            // 请替换成您的AccessKey ID、AccessKey Secret。
            IClientProfile profile = DefaultProfile.GetProfile(
                "cn-shanghai",
                "您的AccessKey ID",
                "您的AccessKey Secret");
            DefaultAcsClient client = new DefaultAcsClient(profile);

            DeleteFacesRequest request = new DeleteFacesRequest();
            request.AcceptFormat = FormatType.JSON;
            request.ContentType = FormatType.JSON;
            request.Method = MethodType.POST;
            request.Encoding = "UTF-8";

            /**
            * personId:用户自定义个体ID,必填。
            * faceIds:已添加的人脸ID。
            */
            Dictionary<string, object> httpBody = new Dictionary<string, object>();
            httpBody.Add("personId", "个体ID");
            httpBody.Add("faceIds", new List<string> { "人脸ID_1", "人脸ID_2" });

            request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)), "utf-8", FormatType.JSON);
            try
            {
                DeleteFacesResponse response = client.GetAcsResponse(request);


                if (response.HttpResponse.Status != 200)
                {
                    Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
                }
                Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
    }
}