API:Tokens
From MediaWiki.org
![]() |
This page is part of the MediaWiki API documentation. |
Language: | English • 日本語 |
---|
Quick overview:
- Quick start guide
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Search suggestions
- Parsing wikitext and expanding templates
- Purging pages' caches
- Parameter information
- Changing wiki content
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
- Asserting
MediaWiki version: | 1.20 |
Contents
Obtaining tokens[edit | edit source]
Tokens can be obtained using action=tokens. These tokens can then be used in other API requests.
Parameters[edit | edit source]
- type: the type of token requested. Options:
-
- block
- centralauth
- delete
- deleteglobalaccount
- edit
- import
- move
- options
- patrol
- protect
- setglobalaccountstatus
- unblock
- watch
Examples[edit | edit source]
Getting an edit token (default behavior)
Result |
---|
<?xml version="1.0"?> <api> <tokens edittoken="6c82e3a4f17f52ff1e2e4a16b64fed10+\" /> </api> |
Getting several tokens at once
Result |
---|
<?xml version="1.0"?> <api> <tokens edittoken="6c82e3a4f17f52ff1e2e4a16b64fed10+\" emailtoken="6c82e3a4f17f52ff1e2e4a16b64fed10+\" patroltoken="0eaa2666f8c6c0779c43acbdf9703c4a+\" watchtoken="22dff2c0b0c1bef9ad34673b81b91f22+\" /> </api> |
Possible errors[edit | edit source]
In addition to the usual errors, other errors may be returned in the following format:
<?xml version="1.0"?> <api> <warnings> <tokens>Unrecognized value for parameter 'type': test</tokens> </warnings> <tokens/> </api>
Possible errors include:
- Unrecognized value for parameter 'type'
- Action 'xxx' is not allowed for the current user
Failing to urlencode the token can result in an invalid token error.
Important Note[edit | edit source]
You need to send the cookie obtained in the login phase when you do call the api with the "tokens" action; otherwise you get the cryptic "readapidenied" error.
See also[edit | edit source]
Language: | English • 日本語 |
---|