All Products
Search
Document Center

Initialization

Last Updated: Jan 04, 2021

This topic describes how to initialize ApsaraVideo VOD SDK for PHP by using an AccessKey pair or a Security Token Service (STS) token.

Prerequisites

Initialize the SDK

Determine the region where you want to call ApsaraVideo VOD operations. For more information about the supported regions, see Access regions and IDs. For example, if you want to call the operations in the China (Shanghai) region, use cn-shanghai.

  • Use the AccessKey pair to initialize the SDK. Example:

    require_once './aliyun-php-sdk/aliyun-php-sdk-core/Config.php';   // Assume that your source code file is stored in the same directory as aliyun-php-sdk.
    use vod\Request\V20170321 as vod;
    
    function initVodClient($accessKeyId, $accessKeySecret) {
        $regionId = 'cn-shanghai';  // The region where you want to call ApsaraVideo VOD operations.
        $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
        return new DefaultAcsClient($profile);
    }
                            
  • Use an STS token to initialize the SDK. Example:

    require_once './aliyun-php-sdk/aliyun-php-sdk-core/Config.php';   // Assume that your source code file is stored in the same directory as aliyun-php-sdk.
    use vod\Request\V20170321 as vod;
    
    function initVodClient($accessKeyId, $accessKeySecret, $securityToken) {
        $regionId = 'cn-shanghai';  // The region where you want to call ApsaraVideo VOD operations.
        $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret, $securityToken);
        return new DefaultAcsClient($profile);
    }
                            
Notice

If you fail to call ApsaraVideo VOD operations in other regions, update the aliyun-php-sdk-core SDK to version 1.3.8 or later, and the aliyun-php-sdk-vod SDK to version 2.15.1 or later.