早上起来,突然对TOP平台发生了兴趣,于是注册了一个帐号,抄着他们的例子在GAE(use Django)写了下面的测试代码,还能跑起来。以后有空每天写一两个API测试的片段好了,以为娱乐。
def index(request):
logging.info(’——-index()———’)
#获得当前时间
t = time.localtime()
apikey = settings.TOP_API_KEY
secretkey = settings.TOP_SECRET_KEY
topurl = ‘http://gw.sandbox.taobao.com/router/rest'
paramArray = {
‘app_key’:apikey,
‘method’:’taobao.taobaoke.items.get’,
‘format’:‘json’,
‘v’:‘1.0’,
’timestamp’:time.strftime(’%Y-%m-%d %X’, t),
‘fields’:‘iid,title,nick,pic_url,price,click_url’,
‘pid’:‘mm_5410_0_0’,
‘cid’:‘1512’,
‘page_no’:‘1’,
‘page_size’:‘6’
}
#生成签名
sign = _sign(paramArray, secretkey);
paramArray[‘sign’] = sign
#组装参数
form_data = urllib.urlencode(paramArray)
logging.info(form_data)
result = urlfetch.fetch(url=topurl,
payload=form_data,
method=urlfetch.POST,
headers={‘Content-Type’: ‘application/x-www-form-urlencoded’})
return HttpResponse(result.content)
返回的结果为:
{"rsp":{"taobaokeItems":[{"click_url":"http://s.click.alimama.com /ma_a?e=7TbRJUSX6oob60193a32e1ad625","id":"72b31835f55b6b6c35beab8c753989c1","nick":" 淘宝客测试数据卖家昵称:1","pict_url":"http://img.taobao.com/bao/uploaded/i2 /T1SxBeXg5XMdMUfdMZ_031728.jpg","price":"100","title":"淘宝客测试数据商品名称:1"}, {"click_url":"http://s.click.alimama.com /ma_a?e=7TbRJUSX6oob60193a32e1ad625","id":"72b31835f55b6b6c35beab8c753989c1","nick":" 淘宝客测试数据卖家昵称:2","pict_url":"http://img.taobao.com/bao/uploaded/i2 /T1SxBeXg5XMdMUfdMZ_031728.jpg","price":"100","title":"淘宝客测试数据商品名称:2"}, {"click_url":"http://s.click.alimama.com /ma_a?e=7TbRJUSX6oob60193a32e1ad625","id":"72b31835f55b6b6c35beab8c753989c1","nick":" 淘宝客测试数据卖家昵称:3","pict_url":"http://img.taobao.com/bao/uploaded/i2 /T1SxBeXg5XMdMUfdMZ_031728.jpg","price":"100","title":"淘宝客测试数据商品名称:3"}, {"click_url":"http://s.click.alimama.com /ma_a?e=7TbRJUSX6oob60193a32e1ad625","id":"72b31835f55b6b6c35beab8c753989c1","nick":" 淘宝客测试数据卖家昵称:4","pict_url":"http://img.taobao.com/bao/uploaded/i2 /T1SxBeXg5XMdMUfdMZ_031728.jpg","price":"100","title":"淘宝客测试数据商品名称:4"}, {"click_url":"http://s.click.alimama.com /ma_a?e=7TbRJUSX6oob60193a32e1ad625","id":"72b31835f55b6b6c35beab8c753989c1","nick":" 淘宝客测试数据卖家昵称:5","pict_url":"http://img.taobao.com/bao/uploaded/i2 /T1SxBeXg5XMdMUfdMZ_031728.jpg","price":"100","title":"淘宝客测试数据商品名称:5"}, {"click_url":"http://s.click.alimama.com /ma_a?e=7TbRJUSX6oob60193a32e1ad625","id":"72b31835f55b6b6c35beab8c753989c1","nick":" 淘宝客测试数据卖家昵称:6","pict_url":"http://img.taobao.com/bao/uploaded/i2 /T1SxBeXg5XMdMUfdMZ_031728.jpg","price":"100","title":"淘宝客测试数据商品名 称:6"}]}}
今天写的一段TOP平台的GAE测试代码
今天写的一段TOP平台的GAE测试代码
...