OSS内容检测

本文介绍了如何使用.NET SDK进行OSS违规检测。

前提条件

已安装.NET依赖。关于安装.NET依赖的具体操作,请参见安装.NET依赖

说明

请一定按照安装.NET依赖页面中的版本安装,否则会导致调用失败。

获取OSS违规检测数据

您可以参考以下代码示例获取OSS违规检测数据:

说明

以下代码仅为简单示例,具体的接口参数请参考OSS违规检测API文档

using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20170823;
using System.Collections.Generic;

namespace csharp_sdk_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            /**
             * 常见获取环境变量方式:
             *     获取RAM用户AccessKey ID:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     获取RAM用户AccessKey Secret:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "建议从环境变量中获取RAM用户AccessKey ID",
                    "建议从环境变量中获取RAM用户AccessKey Secret");
            DefaultAcsClient client = new DefaultAcsClient(profile);

            DescribeOssResultItemsRequest describeKeywordLibRequest = new DescribeOssResultItemsRequest();
            describeKeywordLibRequest.ResourceType = "VIDEO";
            describeKeywordLibRequest.Scene = "porn";
            describeKeywordLibRequest.Stock = false;
            describeKeywordLibRequest.StartDate = "2021-10-11 00:00:00 +0800";
            describeKeywordLibRequest.EndDate = "2021-10-12 15:00:53 +0800";
            try
            {
                DescribeOssResultItemsResponse describeOssResultItemsResponse = client.GetAcsResponse(describeKeywordLibRequest);
                Console.WriteLine(System.Text.Encoding.Default.GetString(describeOssResultItemsResponse.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
    }
}

对OSS的审核结果进行标记

该接口能够对OSS的扫描结果进行标记和操作。如果需要对已检测出结果的内容执行删除、标记为正常并忽略,或者解除冻结等操作,您可以调用本接口。

说明

以下代码仅为简单示例,具体的接口参数请参考OSS违规检测API

using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20170823;
using System.Collections.Generic;

namespace csharp_sdk_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            /**
             * 常见获取环境变量方式:
             *     获取RAM用户AccessKey ID:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     获取RAM用户AccessKey Secret:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "建议从环境变量中获取RAM用户AccessKey ID",
                    "建议从环境变量中获取RAM用户AccessKey Secret");
            DefaultAcsClient client = new DefaultAcsClient(profile);

            MarkOssResultRequest markOssResultRequest = new MarkOssResultRequest();
            markOssResultRequest.ResourceType = "VIDEO";
            markOssResultRequest.Scene = "terrorism";
            markOssResultRequest.Stock = false;
            markOssResultRequest.Ids = JsonConvert.SerializeObject(new List<long> { 24930001L });
            markOssResultRequest.Operation = "ignore";
            try
            {
                MarkOssResultResponse markOssResultResponse = client.GetAcsResponse(markOssResultRequest);
                Console.WriteLine(System.Text.Encoding.Default.GetString(markOssResultResponse.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
    }
}

以文件形式导出OSS违规检测结果

您可以参考以下代码示例通过文件形式导出OSS违规检测结果:

说明

以下代码仅为简单示例,具体的接口参数请参考OSS违规检测API

using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20170823;
using System.Collections.Generic;

namespace csharp_sdk_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            /**
             * 常见获取环境变量方式:
             *     获取RAM用户AccessKey ID:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     获取RAM用户AccessKey Secret:Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "建议从环境变量中获取RAM用户AccessKey ID",
                    "建议从环境变量中获取RAM用户AccessKey Secret");
            DefaultAcsClient client = new DefaultAcsClient(profile);

            ExportOssResultRequest exportOssResultRequest = new ExportOssResultRequest();
            exportOssResultRequest.ResourceType = "VIDEO";
            exportOssResultRequest.Scene = "porn";
            exportOssResultRequest.Stock = false;
            exportOssResultRequest.StartDate = "2021-10-11 00:00:00 +0800";
            exportOssResultRequest.EndDate = "2021-10-12 15:00:53 +0800";
            try
            {
                ExportOssResultResponse exportOssResultResponse = client.GetAcsResponse(exportOssResultRequest);
                Console.WriteLine(System.Text.Encoding.Default.GetString(exportOssResultResponse.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
    }
}