Core REST API/Reference/Pages/Get files
GET | /core/v1/{project}/{language}/page/{title}/links/media
|
---|
Returns information about media files used on a wiki page, up to 100 files.
Examples
curl
# Get media files used on the Earth article on English Wikipedia
$ curl https://api.wikimedia.org/core/v1/wikipedia/en/page/Earth/links/media
Python
# Python 3
# Get media files used on the Earth article on English Wikipedia
import requests
page = 'Earth'
url = 'https://api.wikimedia.org/core/v1/wikipedia/en/page/' + page + '/links/media'
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 media files used on the Earth article on English Wikipedia
$url = 'https://api.wikimedia.org/core/v1/wikipedia/en/page/Earth/links/media';
$authorization = 'Authorization: Bearer YOUR_ACCESS_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 media files used on the Earth article on English Wikipedia
let url = 'https://api.wikimedia.org/core/v1/wikipedia/en/page/Earth/links/media';
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
project
required path |
Project name. For example: wikipedia (encyclopedia articles), commons (images, audio, and video), wiktionary (dictionary entries). List all projects.
|
language
required path |
Language code. For example: ar (Arabic), en (English), es (Spanish). List supported languages.
|
title
required path |
Wiki page title |
Responses
200 | Success: Media files found. Returns files object containing an array of files.
Example
{
"files": [
{
"title": "Commons-logo.svg",
"file_description_url": "//en.wikipedia.org/wiki/File:Commons-logo.svg",
"latest": {
"timestamp": "2016-04-05T22:33:52Z",
"user": {
"id": 161142,
"name": "RHaworth"
}
},
"preferred": {
"mediatype": "DRAWING",
"size": null,
"width": 446,
"height": 599,
"duration": null,
"url": "//upload.wikimedia.org/wikipedia/en/thumb/4/4a/Commons-logo.svg/446px-Commons-logo.svg.png"
},
"original": {
"mediatype": "DRAWING",
"size": 932,
"width": 1024,
"height": 1376,
"duration": null,
"url": "//upload.wikimedia.org/wikipedia/en/4/4a/Commons-logo.svg"
}
}
]
}
|
---|---|
404 | Error: Title not found
Example
{
"messageTranslations": {
"en": "The specified title does not exist"
},
"httpCode": 404,
"httpReason": "Not Found"
}
|
500 | Error: Page contains more than 100 media files
Example
{
"messageTranslations": {
"en": "Too many media links found on title (100 allowed)"
},
"httpCode": 500,
"httpReason": "Internal Server Error"
}
|