API调用示例,使用官方SDK调用API
.NET SDK调用示例代码
using System;
using Top.Api;
using Top.Api.Request;
using Top.Api.Response;
namespace ApiTest
{
public class Program
{
public static void Main(string[] args)
{
// TOP服务地址,正式环境需要设置为http://gw.api.taobao.com/router/rest
string serverUrl = "http://gw.api.tbsandbox.com/router/rest";
string appKey = "test"; // 可替换为您的沙箱环境应用的AppKey
string appSecret = "test"; // 可替换为您的沙箱环境应用的AppSecret
string sessionKey = "test"; // 必须替换为沙箱账号授权得到的真实有效SessionKey
ITopClient client = new DefaultTopClient(serverUrl, appKey, appSecret, "json");
ItemSellerGetRequest req = new ItemSellerGetRequest();
req.Fields = "num_iid,title,nick,price,num";
req.NumIid = 123456789L;
ItemSellerGetResponse rsp = client.Execute(req, sessionKey);
Console.WriteLine(rsp.Body);
if (!rsp.IsError)
{
Console.WriteLine(rsp.Item.Title);
}
}
}
}
该示例是在沙箱环境下调用,获取的是沙箱中的数据。若要获取线上环境的数据,请填写自己创建应用获取过来的AppKey与AppSecret,并更改调用接口的环境地址为线上地址,同时使用线上淘宝账号获取授权SessionKey。