API:ウォッチリストのフィード

This page is a translated version of the page API:Watchlist feed and the translation is 100% complete.
混同しないでください: API:Watchlist.
MediaWiki バージョン:
1.9

Manual:Watchlist フィードを返す GET リクエストです。

APIの説明文書


action=feedwatchlist

(main | feedwatchlist)

Returns a watchlist feed.

Specific parameters:
Other general parameters are available.
feedformat

The format of the feed.

One of the following values: atom, rss
Default: rss
hours

List pages modified within this many hours from now.

Type: integer
The value must be between 1 and 72.
Default: 24
linktosections

Link directly to changed sections if possible.

Type: boolean (details)
allrev

Include multiple revisions of the same page within given timeframe.

Type: boolean (details)
wlowner

Used along with token to access a different user's watchlist.

Type: user, by username
wltoken

A security token (available in the user's preferences) to allow access to another user's watchlist.

wlshow

Show only items that meet these criteria. For example, to see only minor edits done by logged-in users, set show=minor|!anon.

Values (separate with | or alternative): !anon, !autopatrolled, !bot, !minor, !patrolled, !unread, anon, autopatrolled, bot, minor, patrolled, unread
wltype

Which types of changes to show:

edit
Regular page edits.
new
Page creations.
log
Log entries.
external
External changes.
categorize
Category membership changes.
Values (separate with | or alternative): categorize, edit, external, log, new
Default: edit|new|log|categorize
wlexcludeuser

Don't list changes by this user.

Type: user, by any of username, IP, Temporary user, interwiki name (e.g. "prefix>ExampleName") and user ID (e.g. "#12345")
Examples:
Show the watchlist feed.
api.php?action=feedwatchlist [open in sandbox]
Show all changes to watched pages in the past 6 hours.
api.php?action=feedwatchlist&allrev=&hours=6 [open in sandbox]

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 を使うと自分以外の人の個人的なウォッチリストトークンを経由して、その人のウォッチリストのフィードにアクセスが許可されます。 利用者自身のウォッチリストトークンの閲覧とリセットは特別:個人設定を開き、「トークンを管理」から項目を探します。
  • wlexcludeuser パラメータがアクセスできる値は1件に限定されます。クエリ1回で複数の利用者の情報を取得することはできません。
  • この API は JSON を返すことはできません -- レスポンスは常にフィードに対応する xml オブジェクトであり、クエリに format=json を追加してもしなくても影響を受けません。
  • フィードは直近で変更されたページのみ表示します。 API を利用しても、変更されてから72時間以上が経過したページは閲覧できません。
  • 通常のアカウントには利用者自身のウォッチリストを閲覧する権限が既定で付与されますが、ボットの挙動はこれとは異なります。 この権限は、ボットに対して手動で付与する必要があります。 実施するには Special:BotPasswords に関する「ウォッチリストを閲覧」権限のチェックを外します。

関連項目

  • API:ウォッチ - 利用者自身のウォッチリストのページを削除もしくは追加します。
  • API:ウォッチリスト - action=query モジュール。特定の利用者のウォッチリストにある、指定した時間枠のページの一覧を取得。
  • API:Watchlistraw - action=query モジュール。特定の利用者のウォッチリストにある全ページの一覧を取得。