Query person IDs

更新时间:
复制 MD 格式

Use the Content Moderation .NET SDK to retrieve all person IDs in a custom group.

Usage notes

  • Each person must belong to a group. Specifying a groupId returns the IDs of all persons in that group.

  • Use the AI Guardrails API endpoints when calling this SDK. See Endpoints.

  • For the full list of parameters, see API reference for querying person IDs.

Prerequisites

Before you begin, ensure that you have:

  • Installed the .NET dependencies. See Install .NET dependencies and use the required .NET version described there. Using a different version causes subsequent API calls to fail.

Query person IDs in a group

Replace <your-group-id> with the ID of the custom group to query.

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

            // Reuse the client instance to improve performance and avoid repeated connections.
            DefaultAcsClient client = new DefaultAcsClient(profile);

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

            // groupId: required. The ID of the custom group.
            Dictionary<string, object> httpBody = new Dictionary<string, object>();
            httpBody.Add("groupId", "<your-group-id>");

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

            try
            {
                GetPersonsResponse 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("Request failed. Error: {0}", ex.Message);
            }
        }
    }
}
PlaceholderDescriptionExample
<your-group-id>The ID of the custom group to querygroup-001