API:常见问题
本页是MediaWiki Action API帮助文档的一部份。 |
概要
本页面提供有关MediaWiki Action API的部分常见问题的解答 This page is intended for technical contributors and software developers who wish to understand and use the MediaWiki Action API.
请同时阅读API:首页 。该指南回答了这里没有提及的问题,并汇总了其他一些有用的页面。
关于 API
什么是API?
API是英文Application Programming Interface(应用程序接口)的缩写。它定义多个软件中介之间的交互。 有时,API接口允许程序请求由实现该API接口的程序执行操作。 在Mediawiki中,它指的是web-based APIs,它使用HTTP请求响应机制,返回JSON/XML结构化数据。
什么是REST API?
REST 是 表述性状态转移(REpresentational State Transfer)的缩写。 一组指导原则或约束条件定义了 RESTful 系统。RESTful API — 或简称 REST API — 遵循这些原则,因此是一种更快速、更可靠且更具扩展性的服务。
API能做什么?
See some uses of API.
在哪里我可以更多地了解API?
这里有一些资源:
一般
MediaWiki Action API是什么?
MediaWiki 动作 API是一个 RESTful 的Web服务,允许用户执行某些 wiki Special:MyLanguage/API:Main page操作,如页面创建、身份验证、解析、搜索等。
MediaWiki Action API可以用来做什么?
MediaWiki Action API 可用于:
- 访问维基功能。
- 使用维基
- 获取有关维基和公共账户的元信息。
右侧边栏指向 API 支持的许多功能。此外,请参见一些使用 MediaWiki Action API 的维基媒体项目。
如何使用(或调用)MediaWiki Action API?
HTTP请求通常用于调用 Action API。有关详细说明,请阅读教程。
要使用行动API
- 使用Special:ApiSandbox
- 启用浏览器的开发者控制台,并在使用时观察指向
api.php
的网络请求。
什么是模块,子模块和参数?
MediaWiki Action API 有许多模块,我们用它们来执行不同的任务。用技术术语来说,模块是ApiBase的子类。模块需要参数。这些参数可能是(也可能不是)子模块。
请考虑以下请求:
在这里:
action
是主要模块的一个参数。action=query
是另一个模块,它被称为查询模块。list
是查询模块的一个参数。list=search
也是一个模块。它可以被称为action=query
的子模块。srsearch
是搜索模块的一个参数。它保存搜索字符串'abc'。format
是主要模块的一个参数。json
是输出格式。
另外,参见介绍和指南。它描述了action=query
模块的子模块。
如何知道要调用哪个模块和子模块?
MediaWiki行动API很龐大,且擴充功能又進一步擴大了它。 以下是解决API请求的几种方法:
- 在侧边栏中,查找您希望实现的功能,并点击链接获取关于调用哪些模块的信息。
- 自文档化API页面包含所有模块和子模块的列表,并附有简要描述。您可以从主要模块开始,并点击链接查看不同的子模块。(附加
recursivesubmodules=1
查看扩展版本)
在哪里可以找到使用API模块的示例代码?
API文档 页面包含一个“示例”部分,展示了如何使用不同的模块和子模块。[自动生成的文档]也在模块描述后附有示例。
参见Mediawiki-API-demos,获取 Python和JavaScript的代码示例。
如何控制输出格式?
默认输出格式是JSON。其他输出格式已在最新稳定版本的MediaWiki中被弃用或移除,不建议使用。
在旧版本中,您可以在查询字符串中传递&format=someformat
来控制输出格式。
For information, see API:Data formats.
我需要访问令牌吗?
您需要访问令牌才能执行登录、编辑、移动页面等修改操作。
To learn more, refer to API:Tokens or the sidebar category 'Authentication'.
如何使用API进行跨站点请求?
For details, see API:Cross-site requests.
查询结果是否有限制?
Yes, it depends on the query parameter. For example, the results for list
and property
queries cannot exceed 500 for regular users.
The API pages contain information about these limits in the 'Additional notes' section or the 'Limits' section. Note that some modules impose stricter limits under certain conditions.
If you are unsure about what limit to set and just want as many results as possible, set the limit to max
.
API调用是否有限制?
There is no concrete limit. Yet, we recommend making a reasonable number of calls to prevent getting blocked. If you want to make many requests, contact the administrators beforehand.
Also, see API:Etiquette.
在哪里可以获取有关MediaWiki Action API的更新?
You can subscribe to the MediaWiki-API-Announce mailing list for announcements and updates.
什么是Wiki转储,我如何使用它们?
Wikimedia’s data dumps are dumps of wiki collections, content, metadata, search indices, etc. To work with dumps, see using dumps and public dumps.
在哪里可以获得更多帮助?
If you can't find answers in the MediaWiki API documentation or the auto-generated documentation pages, feel free to reach out in the following ways.
- 創建Wikimedia帳號(如果你還沒有)並在API討論頁新增一個主題.
- Ask your question on:
- IRC in the #mediawiki 在线 channel.
- MediaWiki-API mailing list.
Extension developers and wiki owners
How can I create an API module in an extension?
API:Extensions will walk you through the complete process of creating an API module in an extension.
What is the internal structure of the API?
API:Implementation Strategy explains the implementation of the API machinery in MediaWiki Core.
How can I restrict the API usage?
To restrict the API usage, you can either restrict the use of write API or disable individual modules.
For instructions and examples, see API:Restricting API usage.
Errors and troubleshooting
How do I detect an error?
If you encounter an error, the error response from the API will set the MediaWiki-API-Error
HTTP header and return an error structure.
What does this error mean?
Find your error in the list of standard error messages to understand what the error means.
How do I file a bug/feature requests?
You can report bugs and file feature requests on Wikimedia's task tracking tool, Phabricator.
Note:
- Add the MediaWiki-API project tag to your task.
- If your report/request is offered by an extension, add that extension's project. (e.g. MediaWiki-extensions-AbuseFilter, MediaWiki-extensions-FlaggedRevs, etc.)
- Verify for duplicates before creating a new task.
- Understand the task creation terms on Phabricator before proceeding.
See How to report a bug for more details.
Am I facing errors due to my API version?
If a website runs a different version of MediaWiki, it would also run a different version of the API. Some module parameters supported in one version might be deprecated (or removed) in others. Such parameters will throw an exception if used. The API pages document any such deprecations.
See the release notes for information regarding different API versions.