This topic describes how to use the PHP SDK to set person information.
Usage notes
The purpose of setting person information is to add remarks to the corresponding person. Setting person information is an optional step. After you setting information about a person, the information is included in the returned results of custom retrieval. For more information about the parameters, see API operation for setting person information.
You need to use the endpoints of the Content Moderation API to call this SDK. For more information about the endpoints, see Endpoints.
Prerequisites
The dependencies for Content Moderation SDK for PHP are installed. For more information, see Installation.
You must use the required PHP version described in the Installation topic to install the dependencies. Otherwise, subsequent operation calls fail.
Submit a task to set person information
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;
try {
/**
* Note: We recommend that you reuse the instantiated client as much as possible. This improves moderation performance and avoids repeated client connections.
* 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();
/**
* personId: the ID of the custom person. This parameter is required.
* name: the name of the custom person. This parameter is optional.
* note: the remarks. This parameter is optional.
*/
$person = array('personId' => 'Person ID',
'name' => 'Name of the person',
'note' => 'Remarks'
);
$result = Green::v20180509()->setPerson()
->timeout(10) // Set the timeout period to 10 seconds. This setting takes effect only on the current request.
->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 only on the current request.
->body(json_encode($person))
->request();
print_r($result->toArray());
} catch (ClientException $exception) {
echo $exception->getMessage() . PHP_EOL;
} catch (ServerException $exception) {
echo $exception->getMessage() . PHP_EOL;
echo $exception->getErrorCode() . PHP_EOL;
echo $exception->getRequestId() . PHP_EOL;
echo $exception->getErrorMessage() . PHP_EOL;
}