Git Product home page Git Product logo

weibo's Introduction

新浪微博node sdk

特点

  • api可配置化
  • 接口采用promise
  • 最少依赖,专注新浪微博OAuth2.0认证

使用方法

安装

npm install http://github.com/ksky521/weibo/tarball/master

配置

配置app信息

打开 config.json 修改自己的appkey和appsecret

配置api接口

打开 lib/apis.js 配置下微博接口(由于太多,并且不时更新,所以我就没全配置),配置下自己使用的接口,方法参考下本js文件,基本如下:

'接口名称': {
    method: 'get', //请求方法,post或者get,参考api文档
    params: { //默认参数,不用填写appkey和access_token,程序会自动补上
        
    }
}

使用

参考 examplesa/app.js 文件(需要先在本目录执行 npm install 安装依赖模块)

修改host,添加下面内容:

127.0.0.1 testapp.cn

进入 open.weibo.com 设置应用回调地址到 http://testapp.cn/callbak

获取登录链接

weibo.getAuthorizeURL(backURL);

获取access_token

weibo.getAccessToken('code', {
    code: code,
    redirect_uri: backURL
}).done(function(err, data) {
    var realpath = templateDir + 'callback.html';
    html = fs.readFileSync(realpath);
    data = JSON.parse(data);
    data.refresh_token = data.refresh_token || '';
    req.session.refresh_token = data.refresh_token;
    req.session.access_token = data.access_token;
    req.session.uid = data.uid;

    html = bdTemplate(html, data);
    res.end(html);
}).fail(function(err, data) {
    var html;
    if (err) {
        html = fs.readFileSync(templateDir + 'error.html');
    }
    res.end(html);
});

使用api接口

//所有API都支持promise接口
weibo.api('users/show', urlObj).done(function(err, result) {
    console.log(result);
    res.end(JSON.stringify(result));
});

weibo's People

Contributors

ksky521 avatar

Stargazers

刘巍峰 avatar

Watchers

刘巍峰 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.