API:用户信息
Appearance
本页是MediaWiki Action API帮助文档的一部份。 |
MediaWiki版本: | ≥ 1.11 |
使用GET 方法返回有关当前登录用户的信息。
API帮助文档
示例
GET 方式
获取一般用户信息和用户权限。
响应
{
"batchcomplete": "",
"query": {
"userinfo": {
"id": 37494596,
"name": "Zaycodes",
"groups": [
"*",
"user"
],
"rights": [
"createaccount",
"read",
"edit",
"createtalk",
"writeapi",
"viewmywatchlist",
"editmywatchlist",
"viewmyprivateinfo",
"editmyprivateinfo",
...
]
}
}
示例代码
Python
#!/usr/bin/python3
"""
userinfo.py
MediaWiki API Demos
Demo of `Userinfo` module: Get general user info and user rights
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"meta": "userinfo",
"uiprop": "rights",
"format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
<?php
/*
userinfo.php
MediaWiki API Demos
Demo of `Userinfo` module: Get general user info and user rights
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"meta" => "userinfo",
"uiprop" => "rights",
"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 );
var_dump( $result );
JavaScript
/*
userinfo.js
MediaWiki API Demos
Demo of `Userinfo` module: Get general user info and user rights
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
meta: "userinfo",
uiprop: "rights",
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) {console.log(response);})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
userinfo.js
MediaWiki API Demos
Demo of `Userinfo` module: Get general user info and user rights
MIT License
*/
var params = {
action: 'query',
meta: 'userinfo',
uiprop: 'rights',
format: 'json'
};
var api = new mw.Api();
api.get( params ).then( function ( data ) {
console.log( data );
} );
参数历史
- v1.33: 启用
latestcontrib
- v1.24: 启用
unreadcount
- v1.18: 启用
implicitgroups
,registrationdate
,realname
- v1.17: 启用
acceptlang
- v1.16: 启用
changeablegroups
- v1.15: 启用
email
- v1.14: 启用
preferencestoken
- v1.12: 启用
ratelimits
,editcount
补充资料
userinfo
函数的代码位于 ApiQueryUserInfo.php。- 如果您需要访问此处未列出的有关维基媒体项目用户的用户信息,请发送电子邮件至 privacywikimedia.org 以获得进一步帮助。
參見
- API:用户 - 获取其他用户的信息。
- wmdoc:mediawiki-core/master/js/mw.user.html#.options – A way to get the options of a user when scripting.