Delete a person from a group

更新时间:
复制 MD 格式

Use the Content Moderation .NET SDK to remove a custom person from one or more custom groups. This operation unbinds the person from the specified groups — it does not delete the person's information or images.

Use the Content Moderation API endpoints when calling this SDK. For a list of supported endpoints, see Endpoints.

Prerequisites

Before you begin, ensure that you have:

  • Installed the Content Moderation SDK for .NET dependencies. See Installation for instructions

  • The .NET version specified in the Installation topic. Using a different version causes subsequent operation calls to fail

Remove a person from groups

The following example calls DeleteGroupsRequest to unbind a custom person from one or more custom groups. Replace the placeholder values with your actual IDs.

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 your RAM user's AccessKey ID and AccessKey secret from environment variables.
            // Storing credentials in environment variables is more secure than hardcoding them.
            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);

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

            // personId: the ID of the custom person to remove. Required.
            // groupIds: the IDs of the custom groups to remove the person from. Required.
            Dictionary<string, object> httpBody = new Dictionary<string, object>();
            httpBody.Add("personId", "<person-id>");
            httpBody.Add("groupIds", new List<string> { "<group-id-1>", "<group-id-2>" });

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

                if (response.HttpResponse.Status != 200)
                {
                    Console.WriteLine("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: {0}", ex.Message);
            }
        }
    }
}

Replace the following placeholders with actual values:

PlaceholderDescription
<person-id>The ID of the custom person to remove
<group-id-1>, <group-id-2>The IDs of the custom groups to remove the person from. Specify one or more group IDs.

What's next