Delete faces

更新时间:
复制 MD 格式

Use the .NET SDK to remove one or more faces from a custom person record in Content Moderation.

Prerequisites

Before you begin, ensure that you have:

  • Installed the .NET dependencies using the required .NET version. Using a different version causes subsequent API calls to fail.

  • The person ID (personId) of the record you want to update.

  • The face IDs (faceIds) of the faces to delete.

Usage notes

Delete faces

The following example sends a DeleteFacesRequest with a person ID and a list of face IDs. Replace the placeholder values before running the code.

Request parameters

ParameterTypeRequiredDescription
personIdstringYesID of the custom person record.
faceIdsList\<string\>YesIDs of the faces to delete. Pass one or more face IDs.

Code example

Replace <person-id> with the actual person ID, and <face-id-1> and <face-id-2> with the face IDs to delete. Add or remove entries in the faceIds list as needed.

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)
        {
            // Get credentials from environment variables.
            // ALIBABA_CLOUD_ACCESS_KEY_ID: AccessKey ID of your RAM user
            // ALIBABA_CLOUD_ACCESS_KEY_SECRET: AccessKey secret of your RAM user
            DefaultProfile profile = DefaultProfile.GetProfile(
                "cn-shanghai",
                Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));

            // Reuse the client instance across requests to improve performance
            // and avoid repeated connection overhead.
            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";

            // Replace <person-id> with the actual person ID.
            // Replace <face-id-1> and <face-id-2> with the actual face IDs to delete.
            Dictionary<string, object> httpBody = new Dictionary<string, object>();
            httpBody.Add("personId", "<person-id>");
            httpBody.Add("faceIds", new List<string> { "<face-id-1>", "<face-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("Request failed. Status: {0}", response.HttpResponse.Status);
                }
                else
                {
                    Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Request failed: {0}", ex.Message);
            }
        }
    }
}

Expected response

A successful request returns HTTP 200 with a JSON response body.

What's next