This topic describes how to use the PHP software development kit (SDK) to manually review videos.
Feature description
If the video detection results do not meet your expectations, you can perform a manual review. For more information about the parameters, see the Manual Video Moderation API Reference.
You must use the AI Guardrails endpoint to call the service using the SDK. For more information about API endpoints, see Endpoints.
-
The SDK accepts only public video URLs. It does not accept local files or binary data.
-
Supported URL types:
-
HTTP/HTTPS URLs on the Internet. The URL can be up to 2,048 characters in length.
-
Alibaba Cloud Object Storage Service (OSS) URL:
oss://<bucket-name>.<endpoint>/<object-name>. You must grant AI Guardrails access to the destination OSS bucket. The bucket and the AI Guardrails service must be in the same region. For more information, see Grant AI Guardrails access to an OSS bucket.
-
Prerequisites
The PHP dependencies have been installed. For more information, see Install PHP dependencies.
You must use the required PHP version described in the Installation topic to install the dependencies. Otherwise, subsequent operation calls fail.
Submit a video manual review task
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;
try {
/**
* Note: To improve detection performance, reuse the instantiated client. This avoids repeatedly establishing connections.
* Common ways to get environment variables:
* Get the AccessKey ID of the RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
* Get the AccessKey secret of the RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
*/
AlibabaCloud::accessKeyClient('Get AccessKey ID from environment variable', 'Get AccessKey secret from environment variable')
->timeout(10) // 10-second timeout. This setting applies to all requests that use this client unless a request-specific timeout is set.
->connectTimeout(3) // 3-second connection timeout. If the value is less than 1, it is converted to milliseconds. This setting applies to all requests that use this client unless a request-specific timeout is set.
->regionId('cn-shanghai')
->asDefaultClient();
$task1 = array('dataId' => 'Business data ID', 'url' => 'URL of the video to be moderated');
$result = Green::v20180509()->videoAsyncManualScan()
->timeout(10) // 10-second timeout. This request timeout setting is valid only for the current request.
->connectTimeout(3) // 3-second connection timeout. If the value is less than 1, it is converted to milliseconds. This request timeout setting is valid only for the current request.
->body(json_encode(array("tasks" => array($task1),
"callback" => "Webhook address",
"seed" => "Random string")))
->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;
}
Query the result of a video manual review task
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\Green\Green;
try {
/**
* Note: To improve detection performance, reuse the instantiated client. This avoids repeatedly establishing connections.
* Common ways to get environment variables:
* Get the AccessKey ID of the RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
* Get the AccessKey secret of the RAM user: getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
*/
AlibabaCloud::accessKeyClient('Get AccessKey ID from environment variable', 'Get AccessKey secret from environment variable')
->timeout(10) // 10-second timeout. This setting applies to all requests that use this client unless a request-specific timeout is set.
->connectTimeout(3) // 3-second connection timeout. If the value is less than 1, it is converted to milliseconds. This setting applies to all requests that use this client unless a request-specific timeout is set.
->regionId('cn-shanghai')
->asDefaultClient();
$result = Green::v20180509()->videoAsyncManualScanResults()
->timeout(10) // 10-second timeout. This request timeout setting is valid only for the current request.
->connectTimeout(3) // 3-second connection timeout. If the value is less than 1, it is converted to milliseconds. This request timeout setting is valid only for the current request.
->body(json_encode(array('Video manual review task ID')))
->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;
}