Delete faces

Updated at:

Use the Content Moderation SDK for PHP to delete one or more faces from a person in your face library.

Prerequisites

Before you begin, ensure that you have:

  • Installed the Content Moderation SDK for PHP. For installation instructions, see Installation.

  • Used the PHP version required by the installation guide. Using an unsupported version causes subsequent API calls to fail.

Usage notes

  • Both personId and faceIds are required in the request body.

  • Use the Content Moderation API endpoints when calling the SDK. For available endpoints, see Endpoints.

  • For the underlying API reference, see API operation for deleting faces.

Request parameters

ParameterTypeRequiredDescription
personIdStringYesThe ID of the person whose faces you want to delete.
faceIdsArray of stringsYesThe IDs of the faces to delete.

Code example

The following example calls the deleteFaces operation to delete faces from a person.

<?php

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;

try {
    // Reuse the instantiated client to improve performance and avoid repeated connections.
    AlibabaCloud::accessKeyClient(
        getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'),     // AccessKey ID
        getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET')  // AccessKey secret
    )
        ->timeout(10)        // Request timeout: 10 seconds
        ->connectTimeout(3)  // Connection timeout: 3 seconds. If the value is smaller than 1, the unit is milliseconds.
        ->regionId('cn-shanghai')
        ->asDefaultClient();

    $body = [
        'personId' => '<person-id>',      // Required: the ID of the person
        'faceIds'  => ['<face-id-0>'],    // Required: array of face IDs to delete
    ];

    $result = Green::v20180509()->deleteFaces()
        ->timeout(10)        // Request timeout: 10 seconds (overrides client-level setting)
        ->connectTimeout(3)  // Connection timeout: 3 seconds (overrides client-level setting). If the value is smaller than 1, the unit is milliseconds.
        ->body(json_encode($body))
        ->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 with actual values:

PlaceholderDescription
<person-id>The ID of the person returned when you added the person to your face library.
<face-id-0>The ID of a face to delete. Add more face IDs to the array to delete multiple faces at once.

What's next