开发者社区> 问答> 正文

Java语言调用POP API教程

游客886 2018-06-28 11:44:14 1795


1.添加阿里云POP API的SDK


aliyun-java-sdk-core
https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core
<!-- pop api sdk-->
<dependency>
   <groupId>com.aliyun</groupId>
   <artifactId>aliyun-java-sdk-core</artifactId>
   <version>4.0.2</version>
</dependency>
<!-- iot sdk-->
<dependency>
   <groupId>com.aliyun</groupId>
   <artifactId>aliyun-java-sdk-iot</artifactId>
   <version>5.0.0</version>
</dependency>



2.IoT套件POP API调用示例



2.1 以QueryProductList 为例


https://help.aliyun.com/document_detail/69271.html



2.2 调用代码


public class IoTPopApiDemo {

    public static void main(String [] args) throws Exception {

        String accessKey = "自己的accessKey";
        String accessKeySecret = "自己的accessKeySecret";
        String regionId = "cn-shanghai";
        
        String productCode = "Iot";
        String regionIdDomain = String.format("iot.%s.aliyuncs.com",regionId);
        //1.获取client
        DefaultProfile profile = DefaultProfile.getProfile(regionId,accessKey,accessKeySecret);
        DefaultProfile.addEndpoint(regionId, regionId, productCode,regionIdDomain);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        //2.构造iot API的request
        QueryProductListRequest request = new QueryProductListRequest();
        request.setCurrentPage(1);
        request.setPageSize(20);
        //3.发起调用
        QueryProductListResponse response = (QueryProductListResponse)client.getAcsResponse(request);

        System.out.println(JSONObject.toJSONString(response));
    }
}


2.3 返回JSON结构


{
    "Data":{
        "PageCount":1,
        "PageSize":10,
        "CurrentPage":1,
        "List":{
            "ProductInfo":[
                
                {
                    "Description":"二进制",
                    "DataFormat":0,
                    "ProductKey":"a1pWti1bx1v",
                    "NodeType":0,
                    "ProductName":"二进制解析",
                    "DeviceCount":1,
                    "GmtCreate":1526629467000
                },
                {
                    "DataFormat":1,
                    "ProductKey":"a1uqtK9VHcO",
                    "NodeType":0,
                    "ProductName":"安卓温湿度计",
                    "DeviceCount":2,
                    "GmtCreate":1523935911000
                }
            ]
        },
        "Total":2
    },
    "RequestId":"EAB7B35E-A9BE-4988-AE2A-1DE1318DBCAF",
    "Success":true
}


3.IoT套件服务端POP API列表


https://help.aliyun.com/document_detail/69893.html






JSON 物联网 Java API 开发工具 Android开发 数据格式
分享到
取消 提交回答
全部回答(0)

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题