All Products
Search
Document Center

Initialization

Last Updated: Mar 07, 2019

Prerequisites

Initialization

  • Reference resources.
  1. import com.aliyuncs.DefaultAcsClient;
  2. import com.aliyuncs.profile.DefaultProfile;
  3. import com.aliyuncs.profile.IClientProfile;
  4. import com.aliyuncs.exceptions.ClientException;
  5. // You need to reference the relevant class for each API. The following example shows how to call the GetVideoPlayAuth API.
  6. import com.aliyuncs.vod.model.v20170321. GetVideoPlayAuthRequest;
  7. import com.aliyuncs.vod.model.v20170321. GetVideoPlayAuthResponse;
  • Initialize a client.
  1. import com.aliyuncs.profile.DefaultProfile;
  2. import com.aliyuncs.DefaultAcsClient;
  3. // The region of ApsaraVideo for VOD. Enter cn-shanghai for a region in China.
  4. DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKeyId, accessKeySecret);
  • Define the operations to be called (the following example shows how to call the GetVideoPlayAuth operation).
  1. GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client) {
  2. GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
  3. request.setVideoId("Video ID");
  4. GetVideoPlayAuthResponse response = null;
  5. try {
  6. response = client.getAcsResponse(request);
  7. } catch (ServerException e) {
  8. throw new RuntimeException("GetVideoPlayAuthRequest Server failed");
  9. } catch (ClientException e) {
  10. throw new RuntimeException("GetVideoPlayAuthRequest Client failed");
  11. }
  12. response.getPlayAuth(); // The video playback credential.
  13. response.getVideoMeta(); // The video metadata.
  14. return response;
  15. }

Call example

  1. DefaultAcsClient client = new DefaultAcsClient(profile);
  2. getVideoPlayAuth(client);