All Products
Search
Document Center

ApsaraVideo Media Processing:Initialize the SDK client

Last Updated:Aug 28, 2023

You can use Composer to install ApsaraVideo Media Processing (MPS) SDK for PHP of the latest version. MPS SDK for PHP of the latest version is different from that of the earlier version in terms of installation, initialization, and usage. For more information about how to initialize and use MPS SDK for PHP of the latest version, see the instructions in this topic.

Background information

You can use an AccessKey pair to initialize the client of MPS SDK for PHP. This way, the permissions are granted based on an authorization policy and remain valid after they are granted. We recommend that you use an AccessKey pair to initialize the SDK client.

Prerequisites

Usage notes

  • For more information about the sample code of MPS SDK for PHP of the latest version, visit OpenAPI Explorer.

  • You must call Mts::v20140618->${apiName} to create an API request. ${apiName} indicates the name of the API operation that you want to call. The first letter of the operation name must be in lower case. For more information about the API operations that you can call, see List of operations by function.

Obtain an AccessKey pair from environment variables

You can define the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET to configure the default credentials. When you call an API operation, the system reads the AccessKey pair from the default credentials and uses the AccessKey pair to complete authentication.

Procedure

Configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.

  • Linux or macOS

Run the following commands:

export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>

Replace <access_key_id> and <access_key_secret> with your AccessKey ID and AccessKey secret.

  • Windows

    1. Create an environment variable file, add the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET to the file, and then enter your AccessKey ID and AccessKey secret.

    2. Restart the Windows operating system.

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();