项目作者: yu-tou

项目描述 :
taobao api的nodejs sdk
高级语言: JavaScript
项目地址: git://github.com/yu-tou/node-taobao.git
创建时间: 2012-11-07T14:00:09Z
项目社区:https://github.com/yu-tou/node-taobao

开源协议:

下载


node-taobao

taobao api的nodejs sdk

构建中,勿用于生产环境

支持的api(增加中)

this.taobaoke=this._taobaoke();
this.products=this._products();
this.user=this._user();
this.users=this._users();
this.item=this._item();

调用示例(oauth认证和测试一个淘客接口)

  1. var Taobao = require("../lib/index.js");
  2. var underscore=require("underscore");
  3. var path=require("path")
  4. var config = {
  5. app_key:"21261604",
  6. app_secret:"31ef78b08e193a496c6647bedf0dfa3a",
  7. redirect_uri:"http://127.0.0.1:8080/sina_auth_cb"
  8. }
  9. var formatjson = require('formatjson');
  10. var app_auth = {
  11. auth:function (req, res) {
  12. var api = new Taobao(config);
  13. var auth_url = api.oauth.authorize();
  14. res.redirect(auth_url);
  15. res.end();
  16. },
  17. sina_auth_cb:function (req, res) {
  18. var code = req.query.code;
  19. var api = new Taobao(config);
  20. api.oauth.accesstoken(code, function (error,data) {
  21. res.cookie("token", data.access_token);
  22. res.redirect('oauth');
  23. res.end();
  24. })
  25. }
  26. }
  27. //import some libs
  28. var express = require('express');
  29. var cons = require('consolidate');
  30. //init express app
  31. var app = express();
  32. app.use(express.logger({
  33. format:':method :url :status'
  34. }));
  35. //设置文件上传临时文件夹
  36. app.use(express.bodyParser({
  37. uploadDir:'./uploads'
  38. }));
  39. app.use(express.cookieParser());
  40. app.use(express.session({
  41. secret:'yutou'
  42. }));
  43. app.use(app.router);
  44. app.use(express.errorHandler({
  45. dumpExceptions:true,
  46. showStack:true
  47. }));
  48. app.error = function (err, req, res) {
  49. console.log("500:" + err + " file:" + req.url)
  50. res.render('500');
  51. }
  52. //设置模板引擎为mustache,这里使用了consolidate库
  53. app.engine("html", cons.mustache);
  54. //设置模板路径
  55. app.set('views', __dirname + '/views');
  56. app.set('view engine', 'html');
  57. app.set('view options', {
  58. layout:false
  59. })
  60. app.listen("8080")
  61. //获取authorize url
  62. app.get("/auth", app_auth.auth)
  63. //获取accesstoken ,存储,并设置userid到cookie
  64. app.get("/sina_auth_cb", app_auth.sina_auth_cb)
  65. //中间页面,提醒用户认证成功
  66. app.get('/oauth', function (req, res) {
  67. var config = {
  68. app_key:"21261604",
  69. app_secret:"31ef78b08e193a496c6647bedf0dfa3a",
  70. redirect_uri:"http://127.0.0.1:8080/sina_auth_cb",
  71. access_token:req.cookies.token
  72. }
  73. var api=new Taobao(config)
  74. api.taobaoke['items.detail.get']({
  75. nick:"xinyu1987326",
  76. num_iids:"13210257235",
  77. fields:"click_url,title,nick,shop_click_url,item_img"
  78. },function(error,data){
  79. console.log(formatjson(data))
  80. })
  81. res.render("oauth.html")
  82. });