This topic describes how to initialize ApsaraVideo VOD SDK for Java by using an AccessKey pair or a Security Token Service (STS) token.
Prerequisites
- An Alibaba Cloud account is created. To create an Alibaba Cloud account, visit the account registration page. Real-name verification is completed. ApsaraVideo VOD is activated.
- An AccessKey pair is created to call ApsaraVideo VOD operations. You can create the AccessKey pair of your Alibaba Cloud account in the User Management console. Alternatively, you can create a RAM user in the RAM console and grant the RAM user the permissions on ApsaraVideo VOD. For more information, see Create and grant permissions to a RAM user.
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; }