All Products
Search
Document Center

Content Moderation:Initialization

Last Updated:Jul 31, 2023

Before you use Content Moderation SDK for PHP to initiate an API request, you must create a client instance and modify the client configurations as needed.

Background information

When you create a client 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.

Create a client instance to moderate images, audio, videos, and text

The following regions are supported:

  • cn-shanghai: China (Shanghai)

  • cn-beijing: China (Beijing)

  • cn-shenzhen: China (Shenzhen)

  • ap-southeast-1: Singapore

Use the following code to create a client instance to moderate images, audio, videos, and text:

/**
 * Common ways to obtain environment variables:
 * Obtain the AccessKey ID of your RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
 * Obtain the AccessKey secret of your RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
 */
AlibabaCloud::accessKeyClient('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')
    ->timeout(10) // Set the timeout period to 10 seconds. This setting takes effect on the requests that are sent by using the client and that have no separate settings. 
    ->connectTimeout(3) // Set the connection timeout period to 3 seconds. If the value of this parameter is smaller than 1, the unit of this parameter is milliseconds. This setting takes effect on the requests that are sent by using the client and that have no separate settings. 
    ->regionId('cn-shanghai')
    ->asDefaultClient();
Note

If you create a client instance in a region other than the China (Shanghai) region, for example, cn-beijing, replace cn-shanghai in the preceding code with the ID of the region.