API:Tokens/de

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page API:Tokens and the translation is 17% complete.

Other languages:
Deutsch • ‎English • ‎dansk • ‎español • ‎français • ‎polski • ‎português • ‎română • ‎sicilianu • ‎русский • ‎中文 • ‎日本語 • ‎한국어

GET Request to obtain tokens required by data-modifying actions

API:Tokens module provide tokens required by data-modifying actions such as logging, editing or moving a page, and watching or patrolling changes. For each action, you need a specific type of token. For example: if you want to login to a wiki site via the Action API, you would need a token of type “login” to proceed.

This module was introduced in v1.24

API documentation




meta=tokens

(main | query | tokens)

Gets tokens for data-modifying actions.

Parameter:
type

Types of token to request.

Values (separate with | or alternative): createaccount, csrf, deleteglobalaccount, login, patrol, rollback, setglobalaccountstatus, userrights, watch
Default: csrf
Examples:
Retrieve a csrf token (the default).
api.php?action=query&meta=tokens [open in sandbox]
Retrieve a watch token and a patrol token.
api.php?action=query&meta=tokens&type=watch|patrol [open in sandbox]

Beispiel

GET Request

Response

{
    "batchcomplete": "",
    "query": {
        "tokens": {
            "logintoken": "9ed1499d99c0c34c73faa07157b3b6075b427365+\\"
        }
    }
}

Sample code

Tokens.py

/* 

 #!/usr/bin/python3

"""
    tokens.py

    MediaWiki Action API Code Samples
    Demo of `Token` module: Fetch token of type `login`
    MIT license
"""

import requests

S = requests.Session()

URL = "https://mediawiki.org/w/api.php"

PARAMS = {
    'action':"query",
    'meta':"tokens",
    'type':"login",
    'format':"json"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.json()

LOGIN_TOKEN = DATA['query']['tokens']['logintoken']

print(LOGIN_TOKEN)

Mögliche Fehler

Code Info
Unrecognized value for parameter "type": xxx Token type 'xxx is not valid

Parameter history

  • v1.27: Introduced login, createaccount

Siehe auch