漫游的备忘录
淘宝API接口数据调用及签名ASP示例
2012-2-7 漫游

md5.asp文件自备,需要返回的是32位即可。这里示例为读取指定ID的商品,淘宝官方文档为http://api.taobao.com/apidoc/api.htm?path=cid:4-apiId:20。注意页面编码必须为utf8。

从网上可见,签名sign是最多人搞不来的问题,我是折腾了半天,到几乎要放弃时却忽然试成功了。至于其它API及中文处理,请自行摸索。


<%@ CODEPAGE=65001 %>


<% Response.CodePage=65001 %>

<% Response.Charset="UTF-8" %>

<!--#include file="MD5.asp"-->

<%

'固定参数


app_key="12490000"    '假设

app_secret="bbfd210000"    '假设

format="xml"

sign_method="md5"

v="2.0"

num_iid="7986333417"    '假设

fields="title,desc"    '简单点,只调用标题和宝贝详情。全部的话是detail_url,num_iid,title,nick,type,cid,seller_cids,props,input_pids,input_str,desc,pic_url,num,valid_thru,list_time,delist_time,stuff_status,location,price,post_fee,express_fee,ems_fee,has_discount,freight_payer,has_invoice,has_warranty,has_showcase,modified,increment,approve_status,postage_id,product_id,auction_point,property_alias,item_img,prop_img,sku,video,outer_id,is_virtual

method="taobao.item.get"    'API接口名称

temp_date=now

timestamp=year(temp_date)&"-"&right(100+month(temp_date),2)&"-"&right(100+day(temp_date),2) & " " &right(100+hour(temp_date),2)&":"&right(100+minute(temp_date),2)&":"&right(100+second(temp_date),2)    '时间戳,格式为yyyy-mm-dd HH:mm:ss,例如:2008-01-25 20:23:30(2012-02-06+15%3A20%3A07)。淘宝API服务端允许客户端请求时间误差为6分钟。





'签名字串,nick和partner_id不是必须,注意字串的顺序,必须按官网所说的要按参数名称升序排列

str = app_secret

str = str & "app_key" & app_key

str = str & "fields" & fields

str = str & "format" & format

str = str & "method" & method

str = str & "num_iid" & num_iid

str = str & "sign_method" & sign_method

str = str & "timestamp" & timestamp

str = str & "v" & v

str = str & app_secret

sign = ucase(MD5(str))



'发送字串,注意签名字串有什么参数,这里也要一模一样的发送,但不需按顺序

geturl = "http://gw.api.taobao.com/router/rest?sign=" & sign & "&timestamp=" & timestamp & "&v=" & v & "&app_key=" & app_key & "&method=" & method & "&sign_method=" & sign_method & "&format=" & format & "&num_iid=" & num_iid & "&fields=" & fields



'发送接收

set http = Server.CreateObject("Microsoft.XMLHTTP")

http.Open "GET", geturl, false

http.setRequestHeader "Content-type:", "text/xml;charset=utf-8"

http.Send

msg=http.ResponseText

set http = nothing

response.write msg    '输出为XML格式,大家根据需要再进一步截取title及desc

%>
评论:
秦时明月
2012-11-12 22:32 回复
@漫游:出现了  <?xml version="1.0" encoding="utf-8" ?>
- <error_response>
  <code>25</code>
  <msg>Invalid signature</msg>
  </error_response>
- <!-- top049184.cm4
  --> 这个错误是什么原因呢?
漫游
2012-03-22 17:30 回复
@lounger:网页的title?可以先读取该网页,再用正则截取出来,原理跟文章采集类似
lounger
2012-03-20 14:57 回复
请问ASP如何截取TITLE及DESC的值?谢谢