This page is a translated version of the page API:Langlinks and the translation is 100% complete.
MediaWiki版本:
1.11

GET请求获取所有从指定的页面到其他语言的跨语言链接的列表。

API帮助文档

(main | query | langlinks)

Returns all interlanguage links from the given pages.

Specific parameters:
Other general parameters are available.
llprop

Which additional properties to get for each interlanguage link:

url
Adds the full URL.
langname
Adds the localised language name (best effort). Use llinlanguagecode to control the language.
autonym
Adds the native language name.
Values (separate with | or alternative): autonym, langname, url
lllang

Only return language links with this language code.

lltitle

Link to search for. Must be used with lllang.

lldir

The direction in which to list.

One of the following values: ascending, descending
Default: ascending
llinlanguagecode

Language code for localised language names.

Default: en
lllimit

How many langlinks to return.

Type: integer or max
The value must be between 1 and 500.
Default: 10
llcontinue

When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.

llurl
Deprecated.

Whether to get the full URL (cannot be used with llprop).

Type: boolean (details)


示例

GET请求

获取指定页面拥有的语言链接列表。

响应

{
    "continue": {
        "llcontinue": "736|ay",
        "continue": "||"
    },
    "query": {
        "pages": {
            "736": {
                "pageid": 736,
                "ns": 0,
                "title": "Albert Einstein",
                "langlinks": [
                    {
                        "lang": "ab",
                        "*": "\u0410\u043b\u0431\u0435\u0440\u0442 \u0415\u0438\u043d\u0448\u0442\u0435\u0438\u043d"
                    },
                    {
                        "lang": "af",
                        "*": "Albert Einstein"
                    },
                    {
                        "lang": "als",
                        "*": "Albert Einstein"
                    },
                    ...
                ]
            }
        }
    }
}

示例代码

Python

#!/usr/bin/python3

"""
    langlinks.py
    MediaWiki API Demos
    Demo of `Langlinks` module: Get a list of language links that a given page has
    MIT License
"""

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

PARAMS = {
    "action": "query",
    "titles": "Albert Einstein",
    "prop": "langlinks",
    "format": "json"
}

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

print(DATA)

PHP

<?php

/*
    langlinks.php
    MediaWiki API Demos
    Demo of `Langlinks` module: Get a list of language links that a given page has
    MIT License
*/

$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "query",
    "titles" => "Albert Einstein",
    "prop" => "langlinks",
    "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

/*
    langlinks.js
    MediaWiki API Demos
    Demo of `Langlinks` module: Get a list of language links that a given page has
    MIT License
*/

var url = "https://en.wikipedia.org/w/api.php"; 

var params = {
    action: "query",
    titles: "Albert Einstein",
    prop: "langlinks",
    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

/*
	langlinks.js
	MediaWiki API Demos
	Demo of `Langlinks` module: Get a list of language links that a given page has
	MIT License
*/

var params = {
		action: 'query',
		titles: 'Albert Einstein',
		prop: 'langlinks',
		format: 'json'
	},
	api = new mw.Api();

api.get( params ).done( function ( data ) {
	console.log( data );
} );

可能的错误

Code Info
invalidparammix title参数可能必须与lang参数一起使用。

参数历史

  • v1.23: 启用llprop, url, langname, autonym, llinlanguagecode
  • v1.23: 弃用llurl
  • v1.19: 启用lldir
  • v1.18: 启用lllang, lltitle
  • v1.17: 启用llurl
  • v1.13: 启用lllimit, llcontinue

參見