Use the Content Moderation PHP SDK to add a name and remarks to a custom person. This is an optional step — the information appears in custom retrieval results.
For the full API reference, see API operation for setting person information.
Prerequisites
Before you begin, ensure that you have:
Installed the Content Moderation PHP SDK using the required PHP version. See Installation for version requirements and setup steps.
Using an unsupported PHP version causes subsequent API calls to fail.
Usage notes
setPerson adds remarks and a name to a custom person identified by personId. Once set, the name and remarks are returned in custom retrieval results.
This operation is optional.
Use the Content Moderation API endpoints when calling this SDK. See Endpoints.
Example
The following example submits a request to set the name and remarks for a custom person.
Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
personId | Yes | String | The ID of the custom person |
name | No | String | The name of the custom person |
note | No | String | Remarks about the custom person |
Code
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;
try {
// Initialize the client with credentials from environment variables.
// Reuse this client instance across requests to improve performance
// and avoid redundant connections.
AlibabaCloud::accessKeyClient(
getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), // AccessKey ID
getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET') // AccessKey secret
)
->timeout(10) // Client-level request timeout: 10 seconds
->connectTimeout(3) // Client-level connection timeout: 3 seconds
->regionId('cn-shanghai')
->asDefaultClient();
// Build the request body.
// Replace placeholder values with your actual personId, name, and note.
$person = [
'personId' => '<your-person-id>', // Required
'name' => '<person-name>', // Optional
'note' => '<remarks>', // Optional
];
$result = Green::v20180509()->setPerson()
->timeout(10) // Request-level timeout: 10 seconds
->connectTimeout(3) // Request-level connection timeout: 3 seconds
->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;
}Replace the following placeholders:
| Placeholder | Description | Example |
|---|---|---|
<your-person-id> | The ID of the custom person to update | person_001 |
<person-name> | The name to assign to the person | Jane Smith |
<remarks> | Any remarks to attach to the person | Security staff, Building A |