This topic describes how to use Content Moderation SDK for Java to create a business scenario. You can use the business scenario to customize a policy for machine-assisted moderation for the Content Moderation API.

Before you begin

Before you call operations, make the following preparations:
  • Create an AccessKey pair for your Alibaba Cloud account. For more information, see Create an AccessKey pair.
  • Install Java dependencies. For more information, see Installation.
  • Optional:Download and import the Extension.Uploader utility class into your project if you submit an on-premises image or a binary image stream for image moderation.

Create a business scenario

Operation Description Supported region
CreateBizType Creates a business scenario.
  • cn-shanghai: China (Shanghai)
  • cn-beijing: China (Beijing)
  • cn-shenzhen: China (Shenzhen)
  • ap-southeast-1: Singapore (Singapore)

Sample code

// Import the required classes. 

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

 * Use the following code to create a business scenario. 
public class CreateBizTypeRequestSample extends BaseSample {
    public static void main(String[] args) throws Exception {
        // Use the AccessKey ID and AccessKey secret of your Alibaba Cloud account. 
        IClientProfile profile = DefaultProfile
            .getProfile("cn-shanghai", "Your AccessKey ID", "Your AccessKey secret");
            .addEndpoint("cn-shanghai", "cn-shanghai", "Green", "");
        IAcsClient client = new DefaultAcsClient(profile);

        CreateBizTypeRequest createBizTypeRequest = new CreateBizTypeRequest();
        // Set the name of the business scenario that you want to create. 
        createBizTypeRequest.setBizTypeName("The name of the business scenario");
        // Import the configuration of an existing business scenario. This parameter is optional. 
        createBizTypeRequest.setBizTypeImport("The name of an existing business scenario to be imported");
        // Specify whether to import the configuration of an industry template. If you set this parameter to true, you must specify the IndustryInfo parameter. This parameter is optional. 
        // Specify the industry classification. This parameter is required if you set the CiteTemplate parameter to true. Valid values: Social-Registration information-Profile picture and Social-Registration information-Nickname. 
        createBizTypeRequest.setIndustryInfo("Social-Registration information-Profile picture");
        // Specify the response format of the operation. 
        // Specify the request method. 
        // Specify the connection timeout. You can modify the timeout period as needed. Unit: milliseconds. 
        // Specify the read timeout. You can modify the timeout period as needed. Unit: milliseconds. 

        // Send the HTTP request to create a business scenario. 
        try {
            HttpResponse httpResponse = client.doAction(createBizTypeRequest);
            // Check whether the HTTP request is successful. 
            if (httpResponse.isSuccess()) {
                JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "utf-8"));
                System.out.println("create success." + JSON.toJSONString(scrResponse, true));
            } else {
                JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "utf-8"));
                // Check the error message. 
                System.out.println("create not success. " + JSON.toJSONString(scrResponse.get("Message"), true));
        } catch (ServerException e) {
        } catch (ClientException e) {
        } catch (Exception e) {