This topic explains how to install the City Visual Intelligence Engine PHP software development kit (SDK) and start making API calls. You must also install the core library for the Alibaba Cloud PHP SDK.
Debug online and generate SDK examples
OpenAPI Explorer lets you call City Visual Intelligence Engine APIs online, dynamically generate SDK example code, and quickly retrieve interfaces. This tool greatly simplifies the use of APIs. We recommend that you use it.
Prerequisites
To use the Python SDK for the City Visual Intelligence Engine, you need an Alibaba Cloud account and an AccessKey. You can create and manage your AccessKey on the AccessKey Management page in the Alibaba Cloud Management Console, or obtain one from your system administrator.
Make sure that you have activated City Visual Intelligence Engine in the Alibaba Cloud Management Console.
The City Visual Intelligence Engine PHP SDK requires PHP 5.5.0 or a later version. You can run the php -v command to check your PHP version.
Install the City Visual Intelligence Engine PHP SDK
To install the PHP SDK, follow these steps:
Download and install Composer.
For Linux:
curl -sS https://getcomposer.org/installer | phpFor Windows:
Click to download and install Composer.
Run the following command to generate the class mapping.
composer dump-autoload --optimizeRun the following Composer command to install the latest version of the City Visual Intelligence Engine PHP SDK.
php -d memory_limit=-1 composer.phar require alibabacloud/sdkImport the Composer autoloader in your code.
<?php
require __DIR__ . '/vendor/autoload.php';Use the City Visual Intelligence Engine PHP SDK
The following code example shows the three main steps for using the City Visual Intelligence Engine PHP SDK:
Set a global client.
Create an API request and set parameters.
Send the request and handle the response or exceptions.
This example shows how to use the City Visual Intelligence Engine PHP SDK to call the DescribeInstances operation and retrieve existing instances.
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
// Set a global client.
AlibabaCloud::accessKeyClient('yourAccessKeyId', 'yourAccessKeySecret')
->regionId('yourRegionId')
->asGlobalClient();
try {
// Send a custom request.
$result2 = AlibabaCloud::rpcRequest() // Specify the API style.
->product('cityvisual') // Specify the product.
->version('2018-10-30') // Specify the version.
->action('DescribeInstances') // Specify the operation.
->options([
'query' => [
'RegionId' => 'cn-shanghai', // Set parameters.
],
])
->request(); // Send the request.
// Access the Instances field in the result.
print_r($result2['Instances']);
} 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;
}