Query a person list
Use the Content Moderation SDK for PHP to retrieve the IDs of all persons in a person group.
Usage notes
Each person must belong to a person group. When you call this operation with a group ID, it returns the IDs of all persons in that group. For parameter details, see the API operation for querying person IDs.
Use the Content Moderation API endpoints when calling this SDK. For available endpoints, see Endpoints.
Prerequisites
Before you begin, ensure that you have:
The Content Moderation SDK for PHP installed. For installation steps, see Installation
Use the PHP version specified in the Installation topic. An incompatible PHP version causes subsequent operation calls to fail.
Query person IDs
The following example retrieves all person IDs in a specified person group.
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;
try {
// Reuse the client instance across requests to improve performance
// and avoid repeated connection overhead.
// Load credentials from environment variables to keep them out of your code.
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 (values < 1 are treated as milliseconds)
->regionId('cn-shanghai')
->asDefaultClient();
// Set groupId to the ID of the person group to query.
$groupId = ['groupId' => '<your-group-id>'];
$result = Green::v20180509()->getPersons()
->timeout(10) // Request-level timeout: overrides the client-level setting
->connectTimeout(3) // Request-level connection timeout: overrides the client-level setting
->body(json_encode($groupId))
->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 <your-group-id> with the ID of the person group to query.
| Parameter | Type | Required | Description |
|---|---|---|---|
groupId | string | Yes | The ID of the person group to query. |
What's next
API operation for querying person IDs — full parameter reference and response structure