Query face information
Updated at:
Queries the face IDs and face image paths associated with a person, using the Content Moderation SDK for PHP.
Usage notes
Specify a person ID and one or more face IDs to retrieve the corresponding face metadata. For the full parameter reference, see API operation for querying information about face images.
Use the Content Moderation API endpoints when calling this SDK. For endpoint details, see Endpoints.
Prerequisites
Before you begin, ensure that you have:
The Content Moderation SDK for PHP installed. For installation steps, see Installation.
Note
Use the PHP version specified in the Installation guide. Using an unsupported PHP version causes subsequent API calls to fail.
Submit a task to query information about face images
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;
try {
// Reuse the client across requests to improve performance and avoid repeated connections.
// Store your RAM user's AccessKey ID and AccessKey secret in environment variables
// instead of hardcoding them in your code.
AlibabaCloud::accessKeyClient(
getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'),
getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET')
)
->timeout(10) // Request timeout: 10 seconds (applies to all requests from this client)
->connectTimeout(3) // Connection timeout: 3 seconds (applies to all requests from this client).
// If the value is smaller than 1, the unit is milliseconds.
->regionId('cn-shanghai')
->asDefaultClient();
// Specify the person ID and the face IDs to query.
// Both personId and faceIds are required.
$person = [
'personId' => '<your-person-id>',
'faceIds' => ['<your-face-id>'],
];
$result = Green::v20180509()->getFaces()
->timeout(10) // Request timeout: 10 seconds (overrides the client-level setting for this request)
->connectTimeout(3) // Connection timeout: 3 seconds (overrides the client-level setting for this request).
// If the value is smaller than 1, the unit is milliseconds.
->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 with actual values:
| Placeholder | Description | Example |
|---|---|---|
<your-person-id> | The person ID returned when the person was added | person_001 |
<your-face-id> | The face ID to query | face_001 |
Is this page helpful?