goland2020.1版本
1,创建项目
image.png
image.png
GOPROXY=https://goproxy.cn,direct
2 sdk选择
https://github.com/nilorg/go-opentaobao
目前没找到太好的SDK,如果有的话可以告诉我。
3,新建个go文件
复制示例代码
package main
import (
"fmt"
"github.com/nilorg/go-opentaobao"
)
func init() {
opentaobao.AppKey = ""
opentaobao.AppSecret = ""
opentaobao.Router = "http://gw.api.taobao.com/router/rest"
}
func main() {
res, err := opentaobao.Execute("taobao.tbk.item.get", opentaobao.Parameter{
"fields": "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick",
"q": "女装",
"cat": "16,18",
})
if err != nil {
fmt.Println(err)
}
fmt.Println("商品数量:", res.Get("tbk_item_get_response").Get("total_results").MustInt())
var imtes []interface{}
imtes, _ = res.Get("tbk_item_get_response").Get("results").Get("n_tbk_item").Array()
for _, v := range imtes {
fmt.Println("======")
item := v.(map[string]interface{})
fmt.Println("商品名称:", item["title"])
fmt.Println("商品价格:", item["reserve_price"])
fmt.Println("商品链接:", item["item_url"])
}
}
image.png
点击下载对应的包。包名会变成绿色。
image.png
3.写个创建淘口令代码
创建淘口令API如下:https://open.taobao.com/api.htm?docId=31127&docType=2&scopeId=11655
package main
import (
"fmt"
"github.com/nilorg/go-opentaobao"
)
func init() {
opentaobao.AppKey = "你的APPKEY"
opentaobao.AppSecret = "你的secret"
opentaobao.Router = "http://gw.api.taobao.com/router/rest"
}
func main() {
res, err := opentaobao.Execute("taobao.tbk.tpwd.create", opentaobao.Parameter{
"text": "666",
"url": "https://s.click.taobao.com/jvvJypu",
})
if err != nil {
fmt.Println(err)
}
fmt.Println(res.Get("tbk_tpwd_create_response").Get("data").Get("password_simple").MustString() )
}
口令就生成完毕啦。
网友评论