内容审核 MODERATION-查询文档审核作业结果

时间:2024-10-10 14:37:02

查询文档审核作业结果

  1. 本章节对查询文档审核作业结果AK/SK方式使用SDK进行示例说明。

    示例代码中需要配置使用RunQueryDocumentModerationJobRequest类的withJobId配置审核任务的id,配置完成后运行即可。

    服务所在的应用区域和终端节点,详情请查看 地区和终端节点

    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.core.region.Region;
    import com.huaweicloud.sdk.moderation.v3.*;
    import com.huaweicloud.sdk.moderation.v3.model.*;
    
    public class RunQueryDocumentModerationJobSolution {
    
        public static void main(String[] args) {
           // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全
           // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK
            String ak = System.getenv("HUAWEICLOUD_SDK_AK");
            String sk = System.getenv("HUAWEICLOUD_SDK_SK");
            String iamEndpoint = "https://iam.cn-north-7.myhuaweicloud.com";
            String endpoint = "https://moderation.cn-north-7.myhuaweicloud.com";
    
            ICredential auth = new BasicCredentials()
                    .withIamEndpoint(iamEndpoint)
                    .withAk(ak)
                    .withSk(sk);
    
            ModerationClient client = ModerationClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(new Region("cn-north-7", endpoint))
                    .build();
            RunQueryDocumentModerationJobRequest request = new RunQueryDocumentModerationJobRequest();
            request.withJobId("xxxx");
            try {
                RunQueryDocumentModerationJobResponse response = client.runQueryDocumentModerationJob(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
  2. 控制台输出查询文档审核作业结果。
    class RunQueryDocumentModerationJobResponse {
        jobId: 01693238400_90b2f15d730f43958a74b93619f3ab78
        status: succeeded
        result: class DocumentQueryResponseResult {
            suggestion: pass
            details: []
        }
        requestParams: class DocumentQueryResponseRequestParams {
            data: class DocumentQueryResponseRequestParamsData {
                url: http://www.baidu.com
                format: pdf
                frameInterval: null
            }
            eventType: default
            imageCategories: null
            textCategories: null
            videoImageCategories: null
            audioCategories: null
            callback: null
        }
        createTime: 2023-08-29T15:08:12.012Z
        updateTime: 2023-08-29T15:08:13.013Z
        requestId: 33ca3825b6525bdc8cd7ee2502028692
    }
support.huaweicloud.com/sdkreference-moderation/moderation_04_0174.html