Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

This branch is 120 commits behind node-modules:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
gtap
lib
test
.gitignore
.gitmodules
.npmignore
LICENSE.txt
README.md
index.js
mkdoc.sh
package.json
start-test.sh
test.js
weibo.js

README.md

tapi: A weibo(like twitter) API SDK, use on browser client and nodejs server.

Supports:

tapi SDK api base on tsina(weibo) api document: http://open.weibo.com/

Requires:

  • browser client: jquery(for ajax request)
  • server: nodejs

Nodejs Install

$ npm install weibo

How to use

Browser

// Include the `weibo.js` javascript files:

<script type="text/javascript" src="../weibo.js"></script>
<script type="text/javascript">
// load all the lib scripts with urlprefix where the `weibo` directory you put into 
weibo.load('/public/js/weibo');
</script>

var tapi = weibo.tapi;
var appkey = '3434422667', secret = '523f2d0d134bfd5aa138f9e5af828bf9';
tapi.init('tsina', appkey, secret);
tapi.public_timeline({}, function(error, data, xhr) {
    if(error) {
        console.error(error);
    } else {
        console.log(data);
    }
});

Server

var tapi = require('weibo').tapi;
// change appkey to yours
var appkey = '3434422667', secret = '523f2d0d134bfd5aa138f9e5af828bf9';
tapi.init('tsina', appkey, secret);
tapi.public_timeline({}, function(error, data, response) {
    if(error) {
        console.error(error);
    } else {
        console.log(data);
    }
});

Use oauth_middleware

handler oauth login middleware, use on connect, express.

params: function oauth_middleware(login_callback, options)

`login_callback`:
    where login success callback: login_callback(oauth_user, referer, req, res, after_callback)
    you MUST save user info in login_callback.
`options`: {
    `home_url`: use to create login success oauth_callback url with referer header, 
        default is `'http://' + req.headers.host`;
    `login_path`: login url, default is '/oauth'
    `logout_path`: default is '/oauth/logout'
    `callback_path`: default is login_path + '_callback'
    `blogtype_field`: default is 'blogtype', 
        if you want to connect weibo, login url should be '/oauth?blogtype=tsina'
    `error_callback`: function(error, referer, user, req, res, next), 
        if you want to handler error by yourselft.
}

Example:

var weibo = require('weibo')
  , home_url = 'http://localhost';
weibo.init('tsina', appkey, secret);
app.use(weibo.oauth_middleware(function(oauth_user, referer, req, res, callback) {
    // do something ...
    // save oauth_user
    db.save_user(oauth_user);
    // use auth redirect, just callback(), return to login referer page.
    // otherwise, callback(true), and handler redirect by yourself
    callback();
}));

Node Gtap Twitter API Proxy Server

var start_gtap = require('weibo').start_gtap;
Something went wrong with that request. Please try again.