Nodeweibo user guide for a simple encapsulation library for node crawling Weibo data, nodenodeweibo
I. Preface
In July, I had the idea that I would use node to crawl Weibo data, so I simply encapsulated a nodeweibo database. After one year, the function format is changed to the configuration file in the middle of the process. Some other previous projects have also been deprecated to focus more on the front-end and node. js. Occasionally, we can see more than 60 downloads a day. People are constantly using this database, but few downloads are not updated. But yesterday, someone put forward some pertinent suggestions and useful code for the branch of pull request. So I carefully reviewed nodeweibo and released v2.0.3.
Ii. What is nodeweibo?
Nodeweibo: A simple encapsulation of weibo APIs. You can use functions in Node to call weibo APIs.
Github address: https://github.com/vczero/node-weibo
Here is a markdown section. For details, visit https://github.com/vczero/node-weibo.
Install: npm install nodeweibo o
3. Supported APIs
Supported APIs: https://github.com/vczero/node-weibo/blob/master/doc/api.md
Currently, all weiboapis are basically supported. Below are some of them. Thanks to xizhonghua of George Mason University for adding this md.
Iv. demo
Copy codeThe Code is as follows:
Var Weibo = require ('.../nodeweibo'); // require ('nodeweibo ') also works if you have installed nodeweibo O via npm
Var setting = require ('./setting. json'); // get setting (appKey, appSecret, etc .)
/*
+ -------------------------------------------------
(1) registered account: http://open.weibo.com/
(2) Configure your development account in./setting. json.
(3) understand the authentication mechanism of Weibo, that is, oauth2.0.
(4) 3rd is very important. Make sure you understand this open method.
+ -------------------------------------------------
*/
/*
Initialize weibo before using it
*/
Weibo. init (setting );
/*
+ -------------------------------------------------
Example 1: Enable Weibo Certification
After authentication is enabled, a window will be opened in the browser. The url contains the code parameter.
Note: When running one of the examples, you must comment out another example.
+ -------------------------------------------------
*/
Weibo. authorize ();
/*
+ --------------------------------------------------
Example 2: access_token is required.
(1) read the Weibo open platform API
Such as: http://open.weibo.com/wiki/OAuth2/access_token,
Write necessary parameters into the jsonParas object.
(2) print the obtained data in the callback.
(3) code is the code obtained in your browser window.
(4) Note: If you run this example, comment out the 1st examples and call the code function once,
Will be updated with the certification. One user has 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 );
//});
V. Summary
(1) When releasing a package in the current year, try to write all the documents to make it easier for users. This is an attitude.
(2) Since someone uses this package, try to spend some time maintaining the package. At the beginning of this year, someone asked me how to use it.
(3) Learning others' code is a pleasure. The way to appreciate others' work is to improve work efficiency.