Delete a person
Deletes a person from the face library using the Content Moderation SDK for PHP. This operation permanently removes all face images and related information of the person.
Prerequisites
Before you begin, ensure that you have:
Installed the Content Moderation SDK for PHP using the PHP version specified in the Installation topic. Using an unsupported PHP version causes subsequent API calls to fail.
The
personIdof the person to delete.
Usage notes
When you delete a person, all face images and related information of the person are deleted.
Use the Content Moderation API endpoints when calling this SDK. For a list of endpoints, see Endpoints.
For the full parameter reference, see API operation for deleting a person.
Code example
The following example deletes a person using the deletePerson operation.
Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
personId | Yes | String | The ID of the person to delete. |
PHP
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;
try {
// Initialize the client using credentials from environment variables.
// Reuse this client instance across requests to improve 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
->regionId('cn-shanghai')
->asDefaultClient();
$person = [
'personId' => '<your-person-id>', // Required. Replace with the actual person ID.
];
$result = Green::v20180509()->deletePerson()
->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;
}Error handling
| Exception | Information logged |
|---|---|
ClientException | Error message |
ServerException | Error message, error code, request ID, and error detail |