Get link recommendations
GET | /service/linkrecommendation/v1/linkrecommendations/wikipedia/{language}/{title}
|
---|
Get a set of possible links that can be added to improve an article on Wikipedia.
Examples
curl
# Get link recommendations for the Earth article on English Wikipedia
$ curl https://api.wikimedia.org/service/linkrecommendation/v1/linkrecommendations/wikipedia/en/Earth
Python
# Python 3
# Get link recommendations for the Earth article on English Wikipedia
import requests
page = 'Earth'
url = 'https://api.wikimedia.org/service/linkrecommendation/v1/linkrecommendations/wikipedia/en/' + page
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
<?php
// Get link recommendations for the Earth article on English Wikipedia
$url = 'https://api.wikimedia.org/service/linkrecommendation/v1/linkrecommendations/wikipedia/en/Earth';
$token = 'YOUR_ACCESS_TOKEN';
$authorization = 'Authorization: Bearer ' . $token;
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( $authorization ));
curl_setopt( $ch, CURLOPT_USERAGENT, 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)' );
$output = curl_exec( $ch );
curl_close( $ch );
echo( $output );
?>
JavaScript
// Get link recommendations for the Earth article on English Wikipedia
let url = 'https://api.wikimedia.org/service/linkrecommendation/v1/linkrecommendations/wikipedia/en/Earth';
let response = await fetch( url,
{
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Api-User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}
}
);
response.json()
.then(console.log).catch(console.error);
Parameters
language
required path |
Language code: ar (Arabic), bn (Bangla), cs (Czech), es (Spanish), de (German), el (Greek), en (English), fa (Farsi), fr (French), hu (Hungarian), pl (Polish), pt (Portuguese), ro (Romanian), ru (Russian), simple (Simple English), or vi (Vietnamese)
|
title
required path |
Wiki page title |
max_recommendations
optional query |
Maximum number of recommendations to return. Default value is 15. |
threshold
optional query |
Number between 0 and 1 for the threshold to use. Default value is 0.5. |
Responses
200 | Success: Page found. Returns a link set object.
Example
{
"links": [
{
"context_after": " to distin",
"context_before": "cially in ",
"link_index": 0,
"link_target": "Science fiction",
"link_text": "science fiction",
"match_index": 0,
"score": 0.5104129910469055,
"wikitext_offset": 13852
}
],
"links_count": 1,
"page_title": "Earth",
"pageid": 9228,
"revid": 1013965654
}
|
---|