API:すべての利用者
このページは MediaWiki 操作 API の説明文書の一部です。 |
MediaWiki バージョン: | ≧ 1.11 |
登録済みの利用者をその利用者名順にすべて列挙する GET リクエストです。
APIの説明文書
例
GET リクエスト
名前が文字列"Drov"で始まる全ての利用者を一覧表示するGETリクエスト
レスポンス
{
"batchcomplete": "",
"continue": {
"aufrom": "Drovark",
"continue": "-||"
},
"query": {
"allusers": [
{
"userid": 13239275,
"name": "Drov"
},
{
"userid": 7080866,
"name": "Drova"
},
{
"userid": 16013473,
"name": "Drova 82"
},
...
]
}
}
サンプル コード
Python
#!/usr/bin/python3
"""
get_allusers.py
MediaWiki API Demos
Demo of `Allusers` module: Get all users, starting from those whose name
begins with the string, 'Drov'.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"list": "allusers",
"auprefix": "Drov"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
USERS = DATA["query"]["allusers"]
for user in USERS:
print(user["name"])
PHP
<?php
/*
get_allusers.php
MediaWiki API Demos
Demo of `Allusers` module: Get all users, starting from those whose name begins with the string, 'Drov'.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"format" => "json",
"list" => "allusers",
"auprefix" => "Drov"
];
$url = $endPoint . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
$result = json_decode( $output, true );
foreach( $result["query"]["allusers"] as $k => $v ) {
echo( $v["name"] . "\n" );
}
JavaScript
/*
get_allusers.js
MediaWiki API Demos
Demo of `Allusers` module: Get all users, starting from those whose name begins with the string, 'Drov'.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json",
list: "allusers",
auprefix: "Drov"
};
url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
fetch(url)
.then(function(response){return response.json();})
.then(function(response) {
var users = response.query.allusers;
for (var u in users) {
console.log(users[u].name);
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
get_allusers.js
MediaWiki API Demos
Demo of `Allusers` module: Get all users, starting from those
whose name begins with the string, 'Drov'.
MIT License
*/
var params = {
action: 'query',
format: 'json',
list: 'allusers',
auprefix: 'Drov'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var users = data.query.allusers,
u;
for ( u in users ) {
console.log( users[ u ].name );
}
} );
起こりうるエラー
コード | 情報 |
---|---|
augroup-excludegroup | パラメータ group と excludegroup は同時に使えません |
パラメーターの履歴
- v1.12:
auprop=registration
を導入しました
追加的な注記
- このAPIは大文字と小文字を区別するため、
aufrom=DROV
はaufrom=Drov
と同じ結果を返さない。
- All registered usernames are saved and retrieved in capitalized form.
If you are using aufrom
or auprefix
in your query, make sure you are passing them values that start with an uppercase character.
- Although the default behavior is to list any user in the database, we can also limit our response to only those users who belong to a certain group, such as sysops, or bots.
User groups are how MediaWiki grants users certain rights and privileges; see Help:利用者権限と利用者グループ for more details on how this system works.
関連項目
- API:利用者 - finds information about a list of users.