API:监视列表订阅源
Appearance
本页面的主题不是API:Watchlist。
| 本页是MediaWiki Action API帮助文档的一部分。 |
| MediaWiki版本: | ≥ 1.9 |
使用GET request來回傳Manual:Watchlist供稿(feed)。
API帮助文档
示例
如果沒有透過 wlowner 參數指定用戶,則此 API 預設顯示您自己的關注清單動態,或至少顯示您目前登入帳戶的關注清單動態。
GET请求
获取发出请求的帐户的监视列表供稿。
回应
<?xml version="1.0"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Wikipedia - Watchlist [en]</title>
<link>https://en.wikipedia.org/wiki/Special:Watchlist</link>
<description>Watchlist</description>
<language>en</language>
<generator>MediaWiki 1.33.0-wmf.13</generator>
<lastBuildDate>Tue, 22 Jan 2019 16:20:52 GMT</lastBuildDate>
<item>
<title>Article on Watchlist</title>
...
</item>
</channel>
</rss>
示例代码
Python
#!/usr/bin/python3
"""
get_my_watchlist_feed.py
MediaWiki API Demos
Demo of `Feedwatchlist` module: Get the watchlist feed
for the account making the request.
MIT license
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
# Step 1: Retrieve a login token
PARAMS_1 = {
"action": "query",
"meta": "tokens",
"type": "login",
"format": "json"
}
R = S.get(url=URL, params=PARAMS_1)
DATA = R.json()
LOGIN_TOKEN = DATA['query']['tokens']['logintoken']
# Step 2: Send a post request to log in. For this login
# method, Obtain credentials by first visiting
# https://en.wikipedia.org/wiki/Special:BotPasswords/
# See https://www.mediawiki.org/wiki/API:Login for more
# information on log in methods.
PARAMS_2 = {
"action": "login",
"lgname": "user_name",
"lgpassword": "password",
"format": "json",
"lgtoken": LOGIN_TOKEN
}
R = S.post(URL, data=PARAMS_2)
# Step 3: Request the account's own watchlist feed
PARAMS_3 = {
"action": "feedwatchlist"
}
R = S.get(url=URL, params=PARAMS_3)
DATA = R.text
print(DATA)
PHP
<?php
/*
get_my_watchlist_feed.php
MediaWiki API Demos
Demo of `Feedwatchlist` module: Get the watchlist feed
for the account making the request.
MIT license
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$login_Token = getLoginToken(); // Step 1
loginRequest( $login_Token ); // Step 2
get_watchlist_feed(); // Step 3
// Step 1: GET request to fetch login token
function getLoginToken() {
global $endPoint;
$params1 = [
"action" => "query",
"meta" => "tokens",
"type" => "login",
"format" => "json"
];
$url = $endPoint . "?" . http_build_query( $params1 );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, "cookie.txt" );
curl_setopt( $ch, CURLOPT_COOKIEFILE, "cookie.txt" );
$output = curl_exec( $ch );
curl_close( $ch );
$result = json_decode( $output, true );
return $result["query"]["tokens"]["logintoken"];
}
// Step 2: POST request to log in. 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( $logintoken ) {
global $endPoint;
$params2 = [
"action" => "login",
"lgname" => "bot_user_name",
"lgpassword" => "bot_password",
"lgtoken" => $logintoken,
"format" => "json"
];
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $endPoint );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $params2 ) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, "cookie.txt" );
curl_setopt( $ch, CURLOPT_COOKIEFILE, "cookie.txt" );
$output = curl_exec( $ch );
curl_close( $ch );
}
// Step 3: Request the account's own watchlist feed
function get_watchlist_feed() {
global $endPoint;
$params3 = [
"action" => "feedwatchlist",
"format" => "json"
];
$url = $endPoint . "?" . http_build_query( $params3 );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, "cookie.txt" );
curl_setopt( $ch, CURLOPT_COOKIEFILE, "cookie.txt" );
$output = curl_exec( $ch );
curl_close( $ch );
echo( $output );
}
JavaScript
/*
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();
参数历史
- v1.27: 启用
wltype: categorize - v1.25: 启用
wlshow: unread,wlshow: !unread - v1.24: 棄用
linktodiffs - v1.22: 启用
wltype - v1.19: 启用
wlexcludeuser - v1.17: 启用
linktodiffs - v1.16: 启用
wltoken,wlowner - v1.12: 启用
allrev - v1.11: 启用
hours
补充资料
- 此API還可讓您透過其他使用者的私有監視清單令牌存取他們的監視清單動態。 您可以存取Special:Preferences,在
管理令牌下查看或重置您自己的監視清單令牌。 wlexcludeuser參數只能接受一個值;無法在單一查詢中排除多個使用者。- 此API不會傳回JSON——無論是否在查詢中新增
format=json,回應始終是表示feed的xml物件。 - 此feed僅顯示最近修改的頁面。 您透過此API將無法查看72小時前修改的頁面。
- 雖然普通帳戶預設擁有查看自己關注清單的權限,但機器人的工作方式截然不同。 您必須手動授予機器人此權限。 您可以透過在Special:BotPasswords上勾選核對
查看自己的监视列表來達到此功能。
参阅
- API:监视 - 从您自己的监视列表中添加或删除页面。
- API:监视列表 - 是一個
action=query模組;可取得使用者在給定時間內的監視清單中的頁面清單。 - API:Watchlistraw - 是一個
action=query模組;可取得用戶監視清單中所有頁面的清單。