API:令牌(操作)

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page API:Tokens (action) and the translation is 43% complete.
Other languages:
Deutsch • ‎Deutsch (Sie-Form)‎ • ‎English • ‎dansk • ‎español • ‎français • ‎português • ‎română • ‎русский • ‎کوردی • ‎ไทย • ‎中文 • ‎日本語
Since MW 1.24, the action=tokens is deprecated and includes a warning "Please use action=query&meta=tokens instead".

Tokens can be obtained using action=tokens. These tokens can then be used in other API requests.

参数

  • type: the type of token requested.
    • block
    • delete
    • edit
    • email
    • import
    • move
    • options
    • patrol
    • protect
    • unblock
    • watch

      The Central Auth extension on MediaWiki servers adds the following tokens:
    • deleteglobalaccount
    • setglobalaccountstatus

示例

Getting an edit token (default behavior)

Getting several tokens at once

可能的错误

In addition to the usual errors, other errors may be returned in the following format:

<?xml version="1.0"?>
<api>
   <warnings>
      <tokens>无法识别的参数<var>type</var>的值:test。</tokens>
   </warnings>
   <tokens/>
</api>

可能的错误包括:

  • 无法识别的参数type的值:value。
  • 操作“xxx”不允许当前用户使用。

Failing to urlencode the token can result in an invalid token error.

重要提醒

You need to send the cookie obtained in the login phase when you call the api with the "tokens" action; otherwise you get the cryptic "readapidenied" error.