All Products
Search
Document Center

ApsaraVideo VOD:Content moderation

Last Updated:Aug 22, 2023

This topic provides examples on how to call the API operations of the content moderation module. The API operations are encapsulated in ApsaraVideo VOD SDK for Java. You can call the API operations to submit and query automated review jobs. You can also query automated review results and create manual review jobs.

Limits

The automated review feature is supported only in the Singapore region.

Usage notes

  • In this example, an AccessKey pair is used to initialize a client instance.

  • For more information about the request and response parameters of this operation, visit OpenAPI Explorer. You can click API Documentation in the top navigation bar to view information related to the API operation.

  • This topic provides sample code only for some complex API operations. To obtain sample code for other API operations, perform the following operations: Visit Alibaba Cloud OpenAPI Explorer. In the left-side navigation pane, find the API operation whose sample code you want to obtain and specify the required parameters on the Parameters tab. Then, click Initiate Call. On the SDK Sample Code tab, select the language to view and download the sample code.

Initialize a client

Before you use the SDK, initialize a client. For more information, see Initialization.

Submit an automated review job

You can call the SubmitAIMediaAuditJob operation to submit an automated review job.

Click SubmitAIMediaAuditJob to learn more about this API operation.

Query an automated review job

You can call the GetAIMediaAuditJob operation to query details about an automated review job.

Click GetAIMediaAuditJob to learn more about this API operation.

Query automated review results

You can call the GetMediaAuditResult operation to query the results of automated review jobs.

Click GetAIMediaAuditResult to learn more about this API operation.

Query details of automated review results

You can call the GetMediaAuditResultDetail operation to query details of automated review results.

Click GetMediaAuditResultDetail to learn more about this API operation.

Query the timeline of automated review results

You can call the GetMediaAuditResultTimeline operation to query the timeline of automated review results.

Click GetMediaAuditResultTimeline to learn more about this API operation.

Create a manual review job

You can call the CreateAuditRequest operation to create a manual review job.

Click CreateAuditRequest to learn more about this API operation.

Sample code:

import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.CreateAuditRequest;
import com.aliyuncs.vod.model.v20170321.CreateAuditResponse;
import com.alibaba.fastjson.JSONObject;

/**
 * Obtain the AccessKey information.
 */
public static DefaultAcsClient initVodClient() throws ClientException {
    String regionId = "cn-shanghai";  // Specify the region in which ApsaraVideo VOD is activated.
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you do not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked. As a result, the security of all resources in your account is compromised. 
    // In this example, the system reads the AccessKey pair from environment variables to implement authentication for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
}

/**
 * Specify the content for review.
 */
public static String buildAuditContent() throws Exception {
        List<JSONObject> auditContents = new ArrayList<>();

        JSONObject auditContent = new JSONObject();
        auditContent.put("VideoId", "3ebc10160bda481ca9b6858a0b58****"); // The video ID.
        auditContent.put("Status", "Blocked"); // The status of the review job.
        auditContent.put("Reason", "Pornography content"); // If the review status is Blocked, a reason must be provided. The reason can contain a maximum of 128 bytes.
        auditContents.add(auditContent);

        return auditContents.toString();
}

/**
 * Create a manual review job.
 */
public static CreateAuditResponse createAudit(DefaultAcsClient client) throws Exception {
        CreateAuditRequest request = new CreateAuditRequest();
        // The review content.
        request.setAuditContent(buildAuditContent());

        // The returned results.
        return client.getAcsResponse(request);
}

/**
 * Sample code
 * @param args
 */
public static void main(String[] args) throws Exception {
    DefaultAcsClient client = initVodClient();

    try {
        // Submit manual review results.
        CreateAuditResponse response = createAudit(client);
        // Display the ID of the request.
        System.out.println("ResquestId:" + response.getRequestId());
    } catch (Exception e) {
        System.out.println("ErrorMessage:" + e.getLocalizedMessage());
    }
}

Query historical manual review jobs

You can call the GetAuditHistory operation to query historical manual review jobs.

Click GetAuditHistory to learn more about this API operation.

Configure IP addresses in review security groups

You can call the SetAuditSecurityIp operation to configure the IP addresses in a security group.

Click SetAuditSecurityIp to learn more about this API operation.

Query IP addresses in review security groups

You can call the ListAuditSecurityIp operation to query the IP addresses in a security group.

Click ListAuditSecurityIp to learn more about this API operation.