Add a person
Use the Content Moderation PHP SDK to add a custom person to one or more person groups. A person holds identity information for face-based recognition, and groups organize persons for recognition tasks. A person must belong to at least one group when created.
Prerequisites
Before you begin, ensure that you have:
Installed the Content Moderation SDK for PHP. The SDK requires a specific PHP version; using an unsupported version causes operation calls to fail. See Installation
Created the person groups that the person will join. The
groupIdsparameter requires at least one group ID. See API operation for adding a person for group management APIsObtained the Content Moderation API endpoint for your region. See Endpoints
Add a person
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;
try {
// Initialize the client. Reuse this client across requests to improve
// moderation performance and avoid repeated connection overhead.
AlibabaCloud::accessKeyClient(
getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), // AccessKey ID of your RAM user
getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET') // AccessKey secret of your RAM user
)
->timeout(10) // Client-level timeout: 10 seconds
->connectTimeout(3) // Client-level connection timeout: 3 seconds (if value < 1, unit is milliseconds)
->regionId('cn-shanghai')
->asDefaultClient();
// Build the request body.
// personId and groupIds are required; name and note are optional.
$person = [
'personId' => '<person-id>',
'groupIds' => ['<group-id-0>', '<group-id-1>'],
'name' => '<person-name>',
'note' => '<remarks>',
];
$result = Green::v20180509()->addPerson()
->timeout(10) // Request-level timeout: 10 seconds
->connectTimeout(3) // Request-level connection timeout: 3 seconds (if value < 1, unit is milliseconds)
->body(json_encode($person))
->request();
print_r($result->toArray());
} catch (ClientException $e) {
echo $e->getMessage() . PHP_EOL;
} catch (ServerException $e) {
echo $e->getMessage() . PHP_EOL;
echo $e->getErrorCode() . PHP_EOL;
echo $e->getRequestId() . PHP_EOL;
echo $e->getErrorMessage() . PHP_EOL;
}Replace the following placeholders with actual values:
| Placeholder | Description |
|---|---|
<person-id> | ID of the custom person. |
<group-id-0>, <group-id-1> | IDs of the groups the person will join. |
<person-name> | (Optional) Display name of the custom person. |
<remarks> | (Optional) Any additional notes about the person. |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
personId | String | Yes | The ID of the custom person. |
groupIds | Array | Yes | The IDs of the groups to add the person to. |
name | String | No | The display name of the custom person. |
note | String | No | Remarks or additional information about the person. |
What's next
API operation for adding a person — full parameter reference and response fields
Endpoints — choose the endpoint closest to your service region