All Products
Search
Document Center

Initialization

Last Updated: Mar 08, 2019

Prerequisites

Initialization

  • Reference resources.
  1. require_once './aliyun-php-sdk/aliyun-php-sdk-core/Config.php'; // Assume that your source code file is in the same directory as the **aliyun-php-sdk** directory.
  2. use vod\Request\V20170321 as vod;
  • Initialize a client.
  1. function init_vod_client($accessKeyId, $accessKeySecret) {
  2. $regionId = 'cn-shanghai'; // The region of ApsaraVideo for VOD. Enter cn-shanghai for a region in China.
  3. $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
  4. return new DefaultAcsClient($profile);
  5. }

Note: Enter your AccessKey information for accessKeyId and accessKeySecret.

  • Define the operations to be called (the following example shows how to call the GetPlayInfo operation).
  1. // $client indicates the client object returned through the preceding init_vod_client interface.
  2. // $videoId indicates the video ID.
  3. function get_play_info($client, $videoId) {
  4. $request = new vod\GetPlayInfoRequest();
  5. $request->setVideoId($videoId);
  6. $request->setAcceptFormat('JSON');
  7. return $client->getAcsResponse($request);
  8. }

Call example

  1. // Handle exceptions (if any).
  2. try {
  3. $client = init_vod_client('<Your AccessKey ID>', '<Your AccessKey Secret>');
  4. $playInfo = get_play_info($client, 'Your video ID');
  5. var_dump($playInfo);
  6. } catch (Exception $e) {
  7. print $e->getMessage();
  8. }