npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

iweibo

v1.1.4

Published

新浪微博 node sdk 客户端

Downloads

2

Readme

新浪微博node sdk

特点

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

使用方法

安装

npm install iweibo

配置

引入iweibo

var iweibo = require('iweibo');
var Weibo = iweibo.Weibo;

配置app信息

  • iweibo.set(name, options); //设置单条
  • iweibo.set(optionsObject); //设置多条
iweibo.set({
    appkey: 'xxx',
    appsecret: 'xxxxxxxxxx'
})

支持的配置:

var CONFIG = {
    appkey: '',
    appsecret: '',
    oauth_host: 'https://api.weibo.com/oauth2/authorize',
    access_url: 'https://api.weibo.com/oauth2/access_token',
    api_url: 'https://api.weibo.com/2/'
}

配置api接口

  • iweibo.setAPI(apiname, options); //设置单条api
  • iweibo.setAPI(optionsObject); //设置多条api
iweibo.setAPI('statuses/update', {
    method: 'post',
    params: {
        status: 'hello, world',
        visible: 0
    }
});

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

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

    }
}

可以讲接口统一写到一个json或者js文件中,然后使用 require 引入,直接给 setAPI 传入

使用

参考 examples/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));
});

测试方法

  • 进入examples
  • 修改config.json,回调地址需要在open.weibo.com配置好,然后修改自己的host,将回调地址指到127.0.0.1
  • 执行 npm install
  • 访问自己在config.json配置的网站