文档中心 > 基础技术

API调用示例

更新时间:2023/03/09 访问次数:956590

TOP API是基于HTTP/S协议来调用的,任何一种拥有HTTP/S访问库的语言都可以使用,ISV可以采用官方提供的SDK来调用API,也可以根据API协议编写原生代码来调用API。


一、使用官方SDK调用API


1)JAVA调用示例代码

2).NET调用示例代码

3)PHP调用示例代码


官方SDK包含了API的请求封装、参数签名、响应解释、性能优化等功能,更多信息请参考SDK使用说明


二、使用原生代码调用API


1)JAVA调用示例代码

2).NET调用示例代码

3)PHP调用示例代码


三、API调用实践


1. 通过测试工具快速生成请求代码。

选择需要的API名称,输入你的应用appkey、appsecret、sessionkey(如有),和接口请求参数。

提交测试以后,在请求示例中会生成对应开发语言的SDK调用代码。


image.png


2. 复制到代码中


以java代码为例:


import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.ItemSellerGetRequest;
import com.taobao.api.response.ItemSellerGetResponse;

public class ApiTest {

    public static void main(String[] args) throws Exception {
        String url = "http://gw.api.taobao.com/router/rest";
        String appkey = "test"; // 可替换为您的应用的AppKey
        String secret = "test"; // 可替换为您的应用的AppSecret
        String sessionKey = "test"; // 必须替换为授权得到的真实有效SessionKey

        // 以下内容通过测试工具生成
        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
        ItemSellerGetRequest req = new ItemSellerGetRequest();
        req.setFields("num_iid,title,nick,price,num");
        req.setNumIid(628493994111L);
        ItemSellerGetResponse rsp = client.execute(req, sessionKey);

        System.out.println(rsp.getBody());
        if (rsp.isSuccess()) {
            System.out.println(rsp.getItem().getTitle());
        }
    }

}


 

 

 

FAQ

关于此文档暂时还没有FAQ
返回
顶部