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

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