Learn how to initialize an ApsaraVideo Media Processing (MPS) SDK for Java V2.0 client.
Prerequisites
MPS SDK for Java V2.0 is installed. For more information, see Install MPS SDK for Java.
Get the region ID of your MPS service. For example, if your MPS service is deployed in the China (Shanghai) region, the region ID is
cn-shanghai. For a full list of supported regions, see Endpoints.Get an AccessKey pair. You need this to complete identity verification when initializing the client. For more information, see Create an AccessKey pair.
Obtain an AccessKey pair from environment variables
Set the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables to configure the default credentials. When you call an API operation, the SDK reads the AccessKey pair from these environment variables and uses it for authentication. For setup instructions, see Configure environment variables in Linux, macOS, and Windows.
Initialize a client
Create a client to send API requests. The following snippet shows the minimal configuration — set your credentials and endpoint, then instantiate the client.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
// The endpoint of MPS that you want to access.
config.endpoint = "mts.cn-hangzhou.aliyuncs.com";
The following is a complete runnable example:
package com.aliyun.sample;
public class Sample {
/**
* <b>description</b> :
* <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.mts20140618.Client createClient() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "mts.cn-shanghai.aliyuncs.com";
return new com.aliyun.mts20140618.Client(config);
}
}