weibo-node-sdk

码农软件 · 软件分类 · 开源微博工具 · 2020-01-21 15:29:37

软件介绍

weibo node sdk 是新浪微博 Node.js 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配置的网站

本文地址:https://codercto.com/soft/d/23874.html

冷启动

冷启动

高臻臻 / 人民邮电出版社 / 2018-5 / 59.80元

本书针对中小企业做营销没预算、没用户的痛点,系统梳理冷启动项目的思维和策略,帮助营销和运营人员实现项目从0到1再到n的爆发式增长。 全书有两条主线。一条是营销思维线,侧重于如何思考,包括:升级行业、创新文化,寻找营销切入点;挖掘品 牌和个人的亮点、“做轻”产品,打造具有互联网营销特色的冷启动项目;突破思维,把实体经济“做虚”,发挥虚拟经济的价值。另一条是营销策略线,侧重于如何行动,包......一起来看看 《冷启动》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具