个人觉得目前 最好用的Taobao API的NodeJS封装

 

话说,Top API SDK默认只给了四种语言的SDK,没有我大NodeJS,这可怎么行,于是封装了一个。

参考地址

GitHub: https://github.com/xiaoppp/TopAPI-Node

NPM: https://www.npmjs.com/package/topapi-node

 

 

TopAPI SDK for Node.js

Using Es6 promise, all api return promise.

NPM

Platform Compatibility

Using Promise, Generator features of ES6

When using node 0.11.x or greater, you must use the --harmony-generators flag or just --harmony to get access to generators.

When using node 0.10.x and lower or browsers without generator support, you must use gnode and/or regenerator.

io.js is supported out of the box, you can use co without flags or polyfills.

Install

$ npm install topapi-node

Usage

var Top = require("topapi-node");

var top = new Top({
appKey:"",
appSecret: "",
sessionKey: ""
});

var params = {
page_size: 200,
fields: "num_iid,title,price,pic_url,num,seller_cids,modified,list_time,has_showcase"
}

top.taobao_items_onsale_get(params).then(
(data) => {
console.log(data);
},
(err) => console.log(err)
)

Extend Top Apis

Since topAPI has huge APIs, and this only implements some of them, so you have two ways to extend that, both of them were fine.
Maybe the best way is contribute your code into lib/apis file. :)

First way, you can extend the TOPAPI prototype

Top.prototype.taobao_items_onsale_get = function(params) {
let self = this;
let method = "taobao.items.onsale.get";
return new Promise((resolve, reject) => {
self.postAPI(method, params).then(
(body) => {resolve(body.items_onsale_get_response);},
(err) => reject(err)
);
});
}

Second way, postAPI to server

let method = "taobao.items.onsale.get";

var params = {
page_size: 200,
fields: "num_iid,title,price,pic_url,num,seller_cids,modified,list_time,has_showcase"
}

top.postAPI(method, params).then(
(body) => {
console.log(body);
},
(err) => console.log(err)
)

Process Control

Suggest to use CO for process control

co(function*() {
let param = {
parent_id: 0,
picture_category_name: "test"
};

let category = yield top.taobao_picture_category_get(param);

if (category) {
category = yield top.taobao_picture_category_add(param);
}

return Promise.resolve(category);
}

License

(c) Fork Ltd. Licensed under the MIT license.

Using ES6 features Promise Array Function Generator

posted on   xiao_p  阅读(1819)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 单线程的Redis速度为什么快?
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示