Initialize the SDK client
The latest ApsaraVideo Media Processing (MPS) SDK for PHP differs from earlier versions in installation, initialization, and usage. You can initialize the SDK client by using an AccessKey pair to call MPS API operations.
Background information
MPS SDK for PHP supports initialization with an AccessKey pair. Permissions are granted based on an authorization policy and remain valid once granted. We recommend that you use an AccessKey pair to initialize the SDK client.
Prerequisites
-
MPS SDK for PHP is installed. For more information, see Installation.
-
A Resource Access Management (RAM) user is created and authorized to access MPS. For more information, see Create a RAM user and grant permissions to the RAM user.
Usage notes
-
For sample code of the latest MPS SDK for PHP, visit OpenAPI Explorer.
-
Call
Mts::v20140618->${apiName}to create an API request, where${apiName}is the API operation name with the first letter in lowercase. For the list of available operations, see List of operations by function.
Obtain an AccessKey pair from environment variables
Set the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables to configure the default credentials. When you call an API operation, the SDK reads the AccessKey pair from these environment variables and uses it for authentication. For setup instructions, see Configure environment variables in Linux, macOS, and Windows.
Initialize the SDK client
Use an AccessKey pair to initialize the SDK client.
/**
* @param string $accessKeyId
* @param string $accessKeySecret
* @param string $regionId
* @return Mts
* We recommend that you set the protocol parameter to HTTPS in a production environment.
*/
public static function createClient($accessKeyId, $accessKeySecret, $regionId){
$config = new Config([]);
$config->accessKeyId = $accessKeyId;
$config->accessKeySecret = $accessKeySecret;
$config->regionId = $regionId;
$config->protocol = "HTTP";
return new Mts($config);
}
Sample code
In this example, the SearchPipeline operation is called.
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use AlibabaCloud\Darabonba\Env\Env;
use AlibabaCloud\Tea\Tea;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Console\Console;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\SearchPipelineRequest;
class Sample {
/**
* @param string $accessKeyId
* @param string $accessKeySecret
* @param string $regionId
* @return Mts
* We recommend that you set the protocol parameter to HTTPS in a production environment.
*/
public static function createClient($accessKeyId, $accessKeySecret, $regionId){
$config = new Config([]);
$config->accessKeyId = $accessKeyId;
$config->accessKeySecret = $accessKeySecret;
$config->regionId = $regionId;
$config->protocol = "HTTP";
return new Mts($config);
}
/**
* @return void
*/
public static function main(){
$client = self::createClient(Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_ID"), Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"), 'cn-shanghai');
$request = new SearchPipelineRequest([
"state" => "Paused"
]);
$response = $client->searchPipeline($request);
Console::log(Utils::toJSONString(Tea::merge($response->body)));
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main();