This topic provides code examples on how to initialize the SDK for C/C++ by using your AccessKey pair and 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. Example:
#include "vod_sdk/openApiUtil.h" VodCredential initVodClient(std::string accessKeyId, std::string accessKeySecret) { VodCredential authInfo; authInfo.accessKeyId = accessKeyId; authInfo.accessKeySecret = accessKeySecret; authInfo.regionId = "cn-shanghai"; return authInfo; }
- Use an STS token to initialize the SDK. Example:
#include "vod_sdk/openApiUtil.h" VodCredential initVodClient(std::string accessKeyId, std::string accessKeySecret, std::String securityToken) { VodCredential authInfo; authInfo.accessKeyId = accessKeyId; authInfo.accessKeySecret = accessKeySecret; authInfo.securityToken = securityToken; authInfo.regionId = "cn-shanghai"; return authInfo; }
FAQ
- The dynamic link library (DLL) is not installed in the directory where the DLL is
complied or the directory where the DLL is run. What do I do?
Perform the following operations. Example:
You must add the following parameters when you compile the DLL:Add the directory where the DLL is installed to the /etc/ld.so.conf file. Run the ldconfig command.
lcurl ljsoncpp lvod_sdk loss_c_sdk lapr-1 laprutil-1 lmxml
- Which input parameters does the getAcsResponse function support?
The getAcsResponse function is a request function. The following parameters are supported:
- vodCredential: For more information, see Initialize the SDK.
- apiName: The name of the API operation.
- args: The parameters.
- Which function returns a value of the VodApiResponse type?
The getAcsResponse function returns the value of the VodApiResponse type.
- If the request succeeds, the value of httpCode in VodApiResponse is an HTTP status code and the value of result is in the JSON format. You can configure the args parameter to specify the data types of return results.
- If the request fails, the value of httpCode in VodApiResponse is -1 and the value of result is an error message.