Delete a person

更新时间:
复制 MD 格式

Deleting a person removes the person's personId, all associated face images, and all related metadata from your custom face library.

Prerequisites

Before you begin, ensure that you have:

  • Installed the .NET dependencies. For instructions, see Install .NET dependencies.

  • Used the required .NET version described in the Installation topic. Using an unsupported version causes subsequent operation calls to fail.

  • The personId of the person to delete.

Usage notes

Delete a person

The following example sends a DeletePersonRequest with the required personId parameter.

Store your AccessKey ID and AccessKey secret in environment variables instead of hardcoding them in your source code.

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)
        {
            // Load AccessKey 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);

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

            // personId: the ID of the person to delete (required)
            Dictionary<string, object> httpBody = new Dictionary<string, object>();
            httpBody.Add("personId", "<your-person-id>");

            request.SetContent(
                System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)),
                "utf-8",
                FormatType.JSON);

            try
            {
                DeletePersonResponse 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);
            }
        }
    }
}

Replace the placeholder before running the code:

PlaceholderDescription
<your-person-id>The ID of the person to delete

What's next