Query a list of similar image libraries

更新时间:
复制 MD 格式

This topic describes how to use the .NET software development kit (SDK) to perform a paged query for similar image libraries and their element information.

Feature description

You can call this operation to perform a paged query of all similar image libraries and their element information. For more information about the parameters, see the Query a list of similar image libraries API documentation.

You must use the Content Moderation endpoint to call the service using the SDK. For more information about API endpoints, see Endpoints.

Prerequisites

The .NET dependencies must be installed. For instructions, see Install .NET dependencies.

Note

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

Query a list of similar image libraries

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 methods to obtain environment variables:
             *     Obtain the AccessKey ID of the Resource Access Management (RAM) user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     Obtain the AccessKey secret of the RAM user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "<Your AccessKey ID>",
                    "<Your AccessKey Secret>");
            DefaultAcsClient client = new DefaultAcsClient(profile);

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

            Dictionary<string, object> httpBody = new Dictionary<string, object>();
            httpBody.Add("pageSize", "5");
            httpBody.Add("currentPage", "1");
            
            request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)), "utf-8", FormatType.JSON);
            try
            {
                ListSimilarityLibrariesResponse 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("An error occurred: {0}", ex.Message);
            }
        }
    }
}