All Products
Search
Document Center

Content Moderation:Initialization

Last Updated:Aug 07, 2023

IAcsClient is the Java client of aliyun-java-sdk-green, Content Moderation SDK for Java. Before you use aliyun-java-sdk-green to initiate an API request, you must create an IAcsClient instance and modify the IClientProfile configurations as needed.

Background information

When you create an IAcsClient instance, you must specify the region as well as the AccessKey ID and AccessKey secret of your Alibaba Cloud account.

  • For more information about the supported regions, see Endpoints.

  • For more information about how to obtain the AccessKey ID and AccessKey secret of an Alibaba Cloud account, see Obtain an AccessKey pair.

Note

Only specific algorithm models are available in the Singapore, Germany (Frankfurt), and US (Virginia) regions.

Create an IAcsClient instance to moderate images, audio, videos, and text

Use the following code to create an IAcsClient instance to moderate images, audio, videos, and text:

/**
  * The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. To avoid security risks, we recommend that you use a RAM user to call API operations or perform routine O&M.  
  * Common ways to obtain environment variables:
  * Method 1:
  *     Obtain the AccessKey ID of your RAM user: System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
  *     Obtain the AccessKey secret of your RAM user: System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
  * Method 2:
  *     Obtain the AccessKey ID of your RAM user: System.getProperty("ALIBABA_CLOUD_ACCESS_KEY_ID");
  *     Obtain the AccessKey secret of your RAM user: System.getProperty("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
  */
DefaultProfile profile = DefaultProfile.getProfile(
  "cn-shanghai",
  "We recommend that you obtain the AccessKey ID of your RAM user from environment variables",
  "We recommend that you obtain the AccessKey secret of your RAM user from environment variables");
IAcsClient recognitionClient = new DefaultAcsClient(profile);

Create an IAcsClient instance to manage custom image libraries, term libraries, and text pattern libraries

Use the following code to create an IAcsClient instance to manage custom image libraries, term libraries, and text pattern libraries:

/**
  * The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. To avoid security risks, we recommend that you use a RAM user to call API operations or perform routine O&M.  
  * Common ways to obtain environment variables:
  * Method 1:
  *     Obtain the AccessKey ID of your RAM user: System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
  *     Obtain the AccessKey secret of your RAM user: System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
  * Method 2:
  *     Obtain the AccessKey ID of your RAM user: System.getProperty("ALIBABA_CLOUD_ACCESS_KEY_ID");
  *     Obtain the AccessKey secret of your RAM user: System.getProperty("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
  */
DefaultProfile profile = DefaultProfile.getProfile(
  "cn-shanghai",
  "We recommend that you obtain the AccessKey ID of your RAM user from environment variables",
  "We recommend that you obtain the AccessKey secret of your RAM user from environment variables");
IAcsClient managementClient = new DefaultAcsClient(profile);