All Products
Search
Document Center

ApsaraVideo Media Processing:Initialize the SDK client

Last Updated:Aug 29, 2023

This topic describes how to initialize the client of ApsaraVideo Media Processing (MPS) SDK for PHP.

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

function initMtsClient($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai';  // The ID of the region in which your MPS service is deployed.
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}

try {
    $client = initMtsClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
    $response = searchPipeline($client);
    print_r($response);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

Sample code

In this example, the SearchPipeline operation is called.

<?php
require_once './aliyun-php-sdk-core/Config.php'; 
use Mts\Request\V20140618 as Mts;

function initMtsClient($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai';  // The ID of the region in which your MPS service is deployed.
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}


try {
    $client = initMtsClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
    $response = searchPipeline($client);
    print_r($response);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

function searchPipeline($client) {
    $request = new Mts\SearchPipelineRequest();
    $request->setState("Paused");
    $request->setAcceptFormat('JSON');
    return $client->getAcsResponse($request);
}