1. Preface
Just in December last year, I had an idea to use node to crawl the data on Weibo, so I simply encapsulated a nodeweibo library. After a year, there was no maintenance, and the function form was changed to a configuration file in the middle. Some other projects I have done in the past have also been offline, in order to focus more on front-end & node.js. Occasionally, I see that the download volume exceeds 60 per day, and people are constantly using this library, but seeing that the download volume is very small, there is no update. But yesterday, someone pulled request this branch and made some pertinent suggestions and useful code. So I carefully reviewed nodeweibo and released the v2.0.3 version.
2. What is nodeweibo
nodeweibo: Simple encapsulation of weibo's API, you can call the Weibo API in Node using functions.
github project address: https://github.com/vczero/node-weibo
I'll take a screenshot of the markdown here. For details, you can go to https://github.com/vczero/node-weibo.
Installation: npm install nodeweibo
3. Supported APIs
Supported API: https://github.com/vczero/node-weibo/blob/master/doc/api.md
Currently, all weibo APIs are basically supported. The following are some screenshots; thanks to George Mason University for adding this md.
4. demo
The code copy is as follows:
var Weibo = require('../../nodeweibo'); // require('nodeweibo') also works if you have installed nodeweibo via npm
var setting = require('./setting.json'); // get setting (appKey, appSecret, etc.)
/*
+-------------------------------------------------
(1) Register an account: http://open.weibo.com/
(2) Configure your development account in ./setting.json.
(3) Understand the authentication mechanism of Weibo, namely the principle of oauth2.0 authentication.
(4) Point 3 is important to make sure you understand this open approach.
+-------------------------------------------------
*/
/*
initialize weibo before using it
*/
Weibo.init(setting);
/*
+-------------------------------------------------
Example 1: Turn on Weibo Authentication
After starting authentication, a window will be opened in the browser, and the url contains the code parameters.
Note: When running one of the examples, you must comment out the other example.
+-------------------------------------------------
*/
Weibo.authorize();
/*
+--------------------------------------------------
Example 2: Need to obtain access_token
(1) Read Weibo Open Platform API
For example: http://open.weibo.com/wiki/OAuth2/access_token,
Write the necessary parameters into the jsonParas object.
(2) Print out the retrieved data in the callback
(3) Code is the code obtained by your browser window.
(4) Note: If you run this example, please comment out the first example and call the code function once.
Will be updated continuously with the certification. One user, one access_token.
+---------------------------------------------------
*/
// var jsonParas = {
// code:"the value of your browser's parameter code",
// grant_type:"authorization_code"
// };
// Weibo.OAuth2.access_token(jsonParas,function(data){
// console.log(data);
// });
/*
example 3, get public timeline
*/
// // set parameters
// var para = {
// "source": Weibo.appKey.appKey,
// "access_token": 'your access_token here'
// };
// // get public timeline
// Weibo.Statuses.public_timeline(para, function(data){
// console.log(data);
// });
Five: Summary
(1) When publishing a package, try to write the document as much as possible, so that users will be more convenient; this is an attitude.
(2) Since someone uses this package, try to spend some time maintaining this package. At the beginning of this year, someone asked me about how to use it.
(3) Learning other people's code is a pleasure; experiencing other people's work methods is to improve work efficiency.