下载TOP官方JAVA SDK,请参考SDK使用说明文档,如何使用JAVA SDK,请参考Java SDK使用说明文档。
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 serverUrl = "http://gw.api.taobao.com/router/rest";
String appKey = "test"; // 可替换为您的应用的AppKey
String appSecret = "test"; // 可替换为您的应用的AppSecret
String sessionKey = "test"; // 必须替换为授权得到的真实有效SessionKey
TaobaoClient client = new DefaultTaobaoClient(serverUrl, appKey, appSecret);
ItemSellerGetRequest req = new ItemSellerGetRequest();
req.setFields("num_iid,title,nick,price,num");
req.setNumIid(123456789L);
ItemSellerGetResponse rsp = client.execute(req, sessionKey);
System.out.println(rsp.getBody());
if (rsp.isSuccess()) {
System.out.println(rsp.getItem().getTitle());
}
}
}
注:若要获取线上环境的数据,请填写自己创建应用获取过来的AppKey与AppSecret,并更改调用接口的环境地址为线上地址,同时使用线上淘宝账号获取授权SessionKey。