API:Users/fr
Appearance
Cette page fait partie de la documentation de l'API MediaWiki Action. |
Version de MediaWiki : | ≥ 1.12 |
Requête GET pour afficher les informations concernant une liste d'utilisateurs.
Documentation de l'API
Exemple
Requête GET
Fournit une liste des utilisateurs spécifiés -- chaque élément de la liste contenant les informations spécifiées par le paramètre
usprop
api.php? action=query& list=users& ususers=1.2.3.4|Catrope|Vandal01|Bob& usprop=blockinfo|groups|editcount|registration|emailable|gender [Essayez !]
Réponse
{
"batchcomplete": "",
"query": {
"users": [
{
"name": "1.2.3.4",
"invalid": ""
},
{
"userid": 4587601,
"name": "Catrope",
"editcount": 359,
"registration": "2007-06-07T16:36:03Z",
"groups": [
"*",
"user",
"autoconfirmed"
],
"emailable": "",
"gender": "male"
},
{
"name": "Vandal01",
"missing": ""
},
{
"userid": 2793024,
"name": "Bob",
"editcount": 4542,
"registration": "2006-11-18T21:55:03Z",
"groups": [
"extendedconfirmed",
"reviewer",
"*",
"user",
"autoconfirmed"
],
"emailable": "",
"gender": "male"
}
]
}
}
Exemple de code
Python
#!/usr/bin/python3
"""
get_users.py
MediaWiki API Demos
Demo of `Users` module: Get information about several users:
[[1.2.3.4]], [[Catrope]], [[Vandal01]], and [[Bob]]
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"list": "users",
"ususers": "Catrope|Bob",
"usprop": "blockinfo|groups|editcount|registration|emailable|gender"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
USERS = DATA["query"]["users"]
for u in USERS:
print(str(u["name"]) + " has " + str(u["editcount"]) + " edits.")
PHP
<?php
/*
get_users.php
MediaWiki API Demos
Demo of `Users` module: Get information about several users: [[1.2.3.4]], [[Catrope]], [[Vandal01]], and [[Bob]]
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"list" => "users",
"ususers" => "Catrope|Bob",
"usprop" => "blockinfo|groups|editcount|registration|emailable|gender",
"format" => "json"
];
$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"]["users"] as $user ){
echo( $user["name"] . " has " . $user["editcount"] . " edits." . "\n" );
}
JavaScript
/*
get_users.js
MediaWiki API Demos
Demo of `Users` module: Get information about several users: [[1.2.3.4]], [[Catrope]], [[Vandal01]], and [[Bob]]
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
list: "users",
ususers: "Catrope|Bob",
usprop: "blockinfo|groups|editcount|registration|emailable|gender",
format: "json"
};
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.users;
for (var u in users) {
console.log(users[u].name + " has " + users[u].editcount + " edits.");
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
get_users.js
MediaWiki API Demos
Demo of `Users` module: Get information about several users: [[1.2.3.4]], [[Catrope]], [[Vandal01]], and [[Bob]]
MIT License
*/
var params = {
action: 'query',
list: 'users',
ususers: 'Catrope|Bob',
usprop: 'blockinfo|groups|editcount|registration|emailable|gender',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var users = data.query.users,
u;
for ( u in users ) {
console.log( users[ u ].name + " has " + users[ u ].editcount + " edits.");
}
} );
Historique des paramètres
- v1.29:
ususerids
,userrights
ajouté - v1.24:
ustoken
obsolète - v1.18:
implicitgroups
ajouté - v1.17:
rights
ajouté - v1.16:
ususerids
,gender
ajouté - v1.14:
emailable
ajouté - v1.13:
registration
ajouté
Voir aussi
- Aide:Droits utilisateur et groupes - Davantage d'information sur les droits utilisateurs et leur relation avec les groupes
- API:Groupe d'apartenance de l'utilisateur - Ajouter ou supprimer des utilisateurs des groupes
- API:Allusers/fr - Liste les utilisateurs enregistrés, dans l'ordre alphabétique
- Extension:CentralAuth/API - Informations globales sur l'utilisateur