全部产品

SDK

更新时间:2020-08-17 14:21:26

目前阿里云官方提供的SDK分3种语言版本,Java、Python、PHP,具体链接如下:

更多语言版本的SDK,您可以前往阿里云 SDK 服务中进行选择。

相关信息:关于AccessKey的获取

SDK安装

您可以通过添加maven库或者jar包依赖安装SDK,本文以Java语言为示例。

  • 添加maven库

<repositories>
        <repository>
            <id>sonatype-nexus-staging</id>
            <name>Sonatype Nexus Staging</name>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
</repositories> 
  • 添加jar包依赖

<dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>aliyun-java-sdk-alidns</artifactId>
      <version>2.0.10</version>
</dependency>
<dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>aliyun-java-sdk-core</artifactId>
      <version>4.3.2</version>
</dependency>   

示例代码

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.alidns.model.v20150109.*;

public class DescribeGtmInstance {

    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);

        DescribeGtmInstanceRequest request = new DescribeGtmInstanceRequest();
        request.setInstanceId("gtm-cn-xxxxxxxml05");

        try {
            DescribeGtmInstanceResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }

    }
}