weibo-js

Matador compliant library for weibo.com api

npm install weibo-js
1 downloads in the last week
1 downloads in the last month

weibo.js

Matador compliant weib.com API SDK, supporting oAuth flow and general API calls

Usage

Install Matador and Initialize a matador based application

npm install -g matador
matador init matador-app
cd matador-app
npm install matador weibo-js

Register weibo middleware in ./server.js

app.use(matador.session({secret: 'key'}))
app.use(require('weibo-js').middleware({
  appId : 'appId',
  secret : 'appSecret',
  loginUrl: '/auth/login',
  logoutUrl: '/auth/logout',
  callbackUrl: '/auth/callback'
}))

Register a filter in base controller, ./app/controllers/ApplicationController.js

module.exports = require('matador').BaseController.extend(function() {
  this.viewFolder = '';
  this.addBeforeFilter(this.requireAuth)
}).methods({
  requireAuth : function(callback) {
    if(this.request.weibo)
      return callback(null)
    this.response.redirect('/auth/login?redirect=' + this.request.url);
  }
})

Call APIs in sub controller, e.g. ./app/controllers/HomeController.js

module.exports = require(app.set('controllers') + '/ApplicationController').extend(function() {
  this.addExcludeFilter(['index'], this.requireAuth)
}).methods({
  index : function() {
    this.render('index', {
      title : 'The Matador Framework'
    })
  },
  status : function() {
    var that = this;
    this.request.weibo.get('/statuses/friends_timeline.json', function(status) {
      that.json(status);
    }, function(error) {
      console.log(error);
      that.render('500');
    });
  }
})

Contributors

npm loves you