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

weibo-node-api

v1.0.1

Published

A Nodejs weibo api sdk

Downloads

1

Readme

CircleCI

Weibo-node-api

封装了微博 api,在 node-weibo 的基础上用 typescript 重写,并增加了一些新的 api。 🙏vczero !!!

安装

npm install weibo-node-api

一、API 使用说明

(1)阅读新浪微博的API文档 http://open.weibo.com/wiki/%E5%BE%AE%E5%8D%9AAPI

(2)新建实例
const weibo = new Weibo(opts)

(3)请求授权接口作为单独的接口,即在weibo实例上
weibo.authorize()

(4)浏览:http://open.weibo.com/wiki/%E5%BE%AE%E5%8D%9AAPI
   +---------
   比如1:需要使用“OAuth2授权接口”,点击链接到页面底部,看到“OAuth2”,那么OAuth2就是一个类,
   weibo.OAuth2.
   weibo.OAuth2的获取access_token的方法是:weibo.OAuth2.access_token;

   +---------
   比如2:需要使用“微博接口”,那么该类的名称是Statuses.
   则返回最新的公共微博是:public_timeline.
   整个方法的调用是weibo.Statuses.public_timeline.
   +---------

   所有类和函数命名方式尊重新浪微博API方式,以此类推.
(5)所有方法两个参数,第一参数是该接口的参数(json对象格式,不含appKey, appSecret, access_token等参数)

二、example 说明

/*
+-------------------------------------------------
(1)注册账号:http://open.weibo.com/
(2)配置回调url地址和安全域名地址(这两点非常重要)。
+-------------------------------------------------
*/

const Weibo = require('weibo-node-api');

// 首次调用接口前需初始化Weibo类,传入配置信息
const weibo = new Weibo({
  appKey: "2178887180",
  appSecret: "bdb36bac9ce99f78aeb6a2f204c9b8e1",
  redirectUrl: "http://blesstosam.github.io",
  secureDomain: "http://www.github.com"
});

/*
+-------------------------------------------------
1:开启微博认证
启动认证后,将在浏览器器打开一个窗口,url中含有code参数
+-------------------------------------------------
*/

weibo.authorize();

/*
+--------------------------------------------------
2:需要获取access_token
+---------------------------------------------------
*/

const res = await weibo.OAuth2.access_token(
{
  code: "3713366ba477464c7250d41794404c7b",
  grant_type: "authorization_code"
});
console.log(res)

/*
+--------------------------------------------------
例3:调用API发微博
+---------------------------------------------------
*/

const resp = resweibo.Statuses.share(
  {
    source: weibo.opts.appKey,
    access_token: data.access_token,
    status: encodeURI(`just for test! ${weibo.opts.secureDomain}`)
  });
console.log(resp)

三、测试 appkey

(1)如需开发,请自行申请微博开放平台的开发者账号信息。
(2)提供 appkey 仅为测试所用,勿用于实际开发,否则我更改了账号信息会影响您的应用正常使用。
(3)测试的应用信息如下。

{
  "appKey":"2178887180",
  "appSecret":"bdb36bac9ce99f78aeb6a2f204c9b8e1",
  "redirectUrl":"127.0.0.1:3000"
}

四、微博 API 文档

微博 API 文档

五、吐槽 - 微博的 api 真是难用啊!