This topic describes how to initialize ApsaraVideo VOD SDK for Java 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.
    import com.aliyuncs.profile.DefaultProfile;
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    
    public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
        String regionId = "cn-shanghai";  // The region where you want to call ApsaraVideo VOD operations.
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        return client;
    }
  • Use an STS token to initialize the SDK.
    import com.aliyuncs.profile.DefaultProfile;
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    
    public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret, String securityToken) throws ClientException {
        String regionId = "cn-shanghai";  // The region where you want to call ApsaraVideo VOD operations.
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret, securityToken);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        return client;
    }