API | 操作描述 |
用于提交一个文本审核任务 | |
用于查询指定的文本审核任务 |
using COSXML.Model.CI;using COSXML.Auth;using System;using System.Threading;using COSXML;namespace COSSnippet{public class SubmitTextCensorJobModel {private CosXml cosXml;SubmitTextCensorJobModel() {CosXmlConfig config = new CosXmlConfig.Builder().SetRegion("COS_REGION") // 设置默认的地域, COS 地域的简称请参照 https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1.Build();string secretId = "SECRET_ID"; // 云 API 密钥 SecretId, 获取 API 密钥请参照 https://console.tencentcloud.com/cam/capistring secretKey = "SECRET_KEY"; // 云 API 密钥 SecretKey, 获取 API 密钥请参照 https://console.tencentcloud.com/cam/capilong durationSecond = 600; //每次请求签名有效时长,单位为秒QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId,secretKey, durationSecond);this.cosXml = new CosXmlServer(config, qCloudCredentialProvider);}/// 提交文本审核任务public string SubmitTextCensorJob(){// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerstring bucket = "examplebucket-1250000000"; // 注意:此操作需要 bucket 开通内容审核相关功能SubmitTextCensorJobRequest request = new SubmitTextCensorJobRequest(bucket);request.SetCensorObject("text.txt"); // 媒体文件的对象键,需要替换成桶内存在的媒体文件的对象键// 审核的场景类型,有效值:Porn(涉黄)、Ads(广告),可以传入多种类型,不同类型以逗号分隔,例如:Porn,Adsrequest.SetDetectType("Porn,Ads");// 执行请求SubmitCensorJobResult result = cosXml.SubmitTextCensorJob(request);Console.WriteLine(result.GetResultInfo());Console.WriteLine(result.censorJobsResponse.JobsDetail.JobId);Console.WriteLine(result.censorJobsResponse.JobsDetail.State);Console.WriteLine(result.censorJobsResponse.JobsDetail.CreationTime);return result.censorJobsResponse.JobsDetail.JobId;//.cssg-snippet-body-end}static void Main(string[] args){SubmitTextCensorJobModel m = new SubmitTextCensorJobModel();/// 提交审核任务string JobId = m.SubmitTextCensorJob();/// 打印唯一标识了此次审核任务的 JobIdConsole.WriteLine("JobId : " + JobId);}}}
using COSXML.Model.CI;using COSXML.Auth;using System;using System.Threading;using COSXML;namespace COSSnippet{public class SubmitTextCensorJobModel {private CosXml cosXml;SubmitTextCensorJobModel() {CosXmlConfig config = new CosXmlConfig.Builder().SetRegion("COS_REGION") // 设置默认的地域, COS 地域的简称请参照 https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1.Build();string secretId = "SECRET_ID"; // 云 API 密钥 SecretId, 获取 API 密钥请参照 https://console.tencentcloud.com/cam/capistring secretKey = "SECRET_KEY"; // 云 API 密钥 SecretKey, 获取 API 密钥请参照 https://console.tencentcloud.com/cam/capilong durationSecond = 600; //每次请求签名有效时长,单位为秒QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId,secretKey, durationSecond);this.cosXml = new CosXmlServer(config, qCloudCredentialProvider);}/// 查询文本审核任务结果public void GetTextCensorJobResult(string JobId){// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerstring bucket = "examplebucket-1250000000"; // 注意:此操作需要 bucket 开通内容审核相关功能GetTextCensorJobRequest request = new GetTextCensorJobRequest(bucket, JobId);// 执行请求GetTextCensorJobResult result = cosXml.GetTextCensorJob(request);Console.WriteLine(result.GetResultInfo());// 读取审核结果Console.WriteLine(result.resultStruct.JobsDetail.JobId);Console.WriteLine(result.resultStruct.JobsDetail.State);Console.WriteLine(result.resultStruct.JobsDetail.CreationTime);Console.WriteLine(result.resultStruct.JobsDetail.Object);Console.WriteLine(result.resultStruct.JobsDetail.SectionCount);Console.WriteLine(result.resultStruct.JobsDetail.Result);Console.WriteLine(result.resultStruct.JobsDetail.PornInfo.HitFlag);Console.WriteLine(result.resultStruct.JobsDetail.PornInfo.Count);Console.WriteLine(result.resultStruct.JobsDetail.AdsInfo.HitFlag);Console.WriteLine(result.resultStruct.JobsDetail.AdsInfo.Count);// 文本节选Section信息for(int i = 0; i < result.resultStruct.JobsDetail.Section.Count; i++){Console.WriteLine(result.resultStruct.JobsDetail.Section[i].StartByte);Console.WriteLine(result.resultStruct.JobsDetail.Section[i].PornInfo.HitFlag);Console.WriteLine(result.resultStruct.JobsDetail.Section[i].PornInfo.Score);Console.WriteLine(result.resultStruct.JobsDetail.Section[i].PornInfo.Keywords);}}static void Main(string[] args){SubmitTextCensorJobModel m = new SubmitTextCensorJobModel();// 输入提交文本审核任务时获取到的 JobIdstring JobId = "xxx";// 查询审核任务结果m.GetTextCensorJobResult(JobId);}}}
本页内容是否解决了您的问题?