Repository navigation
Expand file tree
/
Copy pathget_my_watchlist_feed.js
More file actions
69 lines (60 loc) · 1.63 KB
/
Copy pathget_my_watchlist_feed.js
File metadata and controls
69 lines (60 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
get_my_watchlist_feed.js
MediaWiki API Demos
Demo of `Feedwatchlist` module: Get the watchlist feed
for the account making the request.
MIT license
*/
var request = require('request').defaults({jar: true}),
url = "https://test.wikipedia.org/w/api.php";
// Step 1: GET Request to fetch login token
function getLoginToken() {
var params_1 = {
action: "query",
meta: "tokens",
type: "login",
format: "json"
};
request.get({ url: url, qs: params_1 }, function(error, res, body) {
if (error) {
return;
}
var data = JSON.parse(body);
loginRequest(data.query.tokens.logintoken);
});
}
// Step2: Send a post request to login. Use of main account for login is not
// supported. Obtain credentials via Special:BotPasswords
// (https://www.mediawiki.org/wiki/Special:BotPasswords) for lgname & lgpassword
function loginRequest(login_token) {
var params_2 = {
action: "login",
lgname: "bot_username",
lgpassword: "bot_password",
lgtoken: login_token,
format: "json"
};
request.post({
url: url,
form: params_2,
}, function(error, res, body) {
if (error) {
return;
}
getWatchlistFeed();
});
}
// Step 3: Request the account's own watchlist feed
function getWatchlistFeed() {
var params_3 = {
action: "feedwatchlist"
};
request.get({ url: url, qs: params_3 }, function(error, res, body) {
if (error) {
return;
}
console.log(body);
});
}
// Start From Step 1
getLoginToken();