Updated on 2023-07-17 GMT+08:00

Querying a Task

  1. This section describes how to use the Image Moderation (Asynchronous Batch) SDK for querying a task by AK/SK authentication.

    Replace the AK/SK in the sample code with the actual AK/SK. Set JobId in RunCheckResultRequest to configure the ID of the moderation task, and then execute the code.

    using System;
    using System.Collections.Generic;
    using HuaweiCloud.SDK.Core;
    using HuaweiCloud.SDK.Core.Auth;
    using HuaweiCloud.SDK.Moderation;
    using HuaweiCloud.SDK.Moderation.V2;
    using HuaweiCloud.SDK.Moderation.V2.Model;
    
    namespace RunCheckResultSolution
    {
        class Program
        {
            static void Main(string[] args)
            {
           //Enter your AK/SK.
                const string ak = "<YOUR AK>";
                const string sk = "<YOUR SK>";
    
                var config = HttpConfig.GetDefaultConfig();
                config.IgnoreSslVerification = true;
                var auth = new BasicCredentials(ak, sk);
    
                var client = ModerationClient.NewBuilder()
                        .WithCredential(auth)
                        .WithRegion(ModerationRegion.ValueOf("xxx"))  //Replace xxx with the region where the service is located.
                        .WithHttpConfig(config)
                        .Build();
    
                var req = new RunCheckResultRequest
                {
                    JobId = "2991572e-f503-11eb-a32d-88bd0dde8061"
                };
    
                try
                {
                    var resp = client.RunCheckResult(req);
                    var respStatusCode = resp.HttpStatusCode;
                    Console.WriteLine(respStatusCode);
                    Console.WriteLine(JsonConvert.DeserializeObject(resp.HttpBody));
                }
                catch (RequestTimeoutException requestTimeoutException)
                {
                    Console.WriteLine(requestTimeoutException.ErrorMessage);
                }
                catch (ServiceResponseException clientRequestException)
                {
                    Console.WriteLine(clientRequestException.HttpStatusCode);
                    Console.WriteLine(clientRequestException.ErrorCode);
                    Console.WriteLine(clientRequestException.ErrorMsg);
                }
                catch (ConnectionException connectionException)
                {
                    Console.WriteLine(connectionException.ErrorMessage);
                }
            }
        }
    }
  1. If 200 is displayed on the console, the code is successfully executed. The result of querying the Image Moderation (Asynchronous Batch) task is displayed on the console.
    200
    {'result': {'create_time': '2021-08-04T08:30:41Z',
                'items': [{'category_suggestions': {
                                                    'porn': 'pass',
                                                   },
                           'detail': {'ad': None,
                                      'porn': [{'confidence': 0.9883,
                                                'label': 'normal'},
                                               {'confidence': 0.0039,
                                                'label': 'porn'},
                                               {'confidence': 0.0078,
                                                'label': 'sexy'}],
                           'suggestion': 'pass',
                           'url': 'https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/terrorism.jpg'}],
                'job_id': 'xxx',
                'status': 'finish',
                'update_time': '2021-08-04T08:30:41Z'}}