All Products
Search
Document Center

Content Moderation:Delete a person from a group

Last Updated:Aug 22, 2024

This topic describes how to use the. NET SDK to delete a person from a specified group.

Usage notes

Deleting a person from a group does not delete the information and images of the person, but only unbinds the person from the group. For more information about the parameters, see API operation for deleting a person from a group.

You need to use the endpoints of the Content Moderation API to call this SDK. For more information about the endpoints, see Endpoints.

Prerequisites

The dependencies for Content Moderation SDK for .NET are installed. For more information about how to install the dependencies, see Installation.

Note

You must use the required .NET version described in the Installation topic to install the dependencies. Otherwise, subsequent operation calls fail.

Submit a task to delete a person from a specified group

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)
        {
            /**
             * Common ways to obtain environment variables:
             *     Obtain the AccessKey ID of your RAM user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     Obtain the AccessKey secret of your RAM user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "We recommend that you obtain the AccessKey ID of your RAM user from environment variables",
                    "We recommend that you obtain the AccessKey secret of your RAM user from environment variables");
            // Note: We recommend that you reuse the instantiated client as much as possible. This improves moderation performance and avoids repeated client connections. 
            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. This parameter is required. 
            * groupIds: the IDs of custom groups. This parameter is 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("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);
            }
        }
    }
}