Query person information

更新时间:
复制 MD 格式

Use the Content Moderation .NET SDK to retrieve details about a custom person by person ID.

Prerequisites

Before you begin, make sure you have:

Important

Use the .NET version specified in the installation guide. An incompatible version causes subsequent API calls to fail.

Usage notes

  • Use the AI Guardrails API endpoints when calling this SDK. For a list of endpoints, see Endpoints.

  • For the full parameter reference, see GetPerson API operation.

Query a custom person

The following example calls the GetPerson operation to retrieve information about a custom person.

Request parameters

ParameterTypeRequiredDescription
personIdstringYesThe ID of the custom person to query

Example

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 credentials 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 across requests to improve performance and avoid repeated connections
            DefaultAcsClient client = new DefaultAcsClient(profile);

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

            // Set the person ID to query
            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
            {
                GetPersonResponse 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("Error: {0}", ex.Message);
            }
        }
    }
}

Replace the following placeholder with your actual value:

PlaceholderDescriptionExample
<your-person-id>The ID of the custom person to queryperson_001

What's next