node-sina-weibo
v0.0.10
Published
Sina Weibo API client for node.js
Downloads
16
Readme
A simple node.js OAuth2 client for Sina Weibo API. It is designed to be a low level SDK to gain flexibility and stability.
Without any wrapper APIs, it's like a mirror to the server side APIs. All you need to do is to read the Sina Weibo API and follow the examples below.
If you want some more graceful and comfortable APIs, like: weibo.getUserDetail(), weibo.update() and etc, you can wrap it with your own Class.
Introduction in Chinese
这是一个简单的基于OAuth2的node.js新浪微博API客户端。
它定位于一个底层SDK,以保持其调用的灵活性及接口的稳定性。
它像是一个服务器端API的镜像,没有对接口进行自己的封装,你只需要阅读 新浪微博的API,并参考下面的例子便可成功调用。
如果你想要用更为优雅的接口,例如:weibo.getUserDetail(), weibo.update() 等等,你可以自己封装一些你要用的API到你自己的Wrapper类中。
欢迎在微博上与我沟通@VM-SAM
Example
var weibo = new SinaWeibo(clientId, clientSecret, accessToken);
weibo.GET('users/show',{uid:'1564554685'}, function (err, resultInJson, response) {
if (err) return callback(err);
// do something with resultInJson
});
Example 2: The SPECIAL api - Upload
Upload in node-sina-weibo is special, a files object is separated from the params object.
文件上传的情况在比较特殊,params参数对象分离出了一个files参数
weibo.UPLOAD('statuses/upload',
{ status:'your content' }, { pic:'pathToYourPicture' }, function (err, resultInJson, response) {
if (err) return callback(err);
// do something with resultInJson
}
);
A Typical Authorization Example
For more details, please refer to Sina Weibo Authorization Documentation
请参阅新浪微博授权机制说明
Step 1 : Get the Authorize Url
var weibo = new SinaWeibo(clientId, clientSecret);
var url = weibo.getAuthorizeUrl({
redirect_uri:'http://your-website.com/callback',
response_type:'code'
});
A code will be provided to the http://your-website.com/callback?code=the-code-you-get.
Step 2 : Get the Access Token with the code got in step 1
weibo.getAccessToken({
code:'the-code-got-in-step-1',
grant_type:'authorization_code',
redirect_uri:'http://your-website.com/callback'
}, function (err, result, accessToken) {
if (err) return callback(err);
// your code here.
// weibo.GET(...)
}
);
##Installation
$ npm install node-sina-weibo
#Change History
- v0.0.10
- Oauth2: Update the dependency module oauth to 0.9.15 to fix the "createCredentials() is deprecated, use tls.createSecureContext instead" message.
- Test: more detailed comments