I'm trying to retrieve images from wikimedia using the existing api, but there seems to be no logic in what works and what doesn't.
Here's what i'm doing/have tried:
I'm getting a query of images, from this url.
http://en.wikipedia.org/w/api.php?action=query&list=allimages&aiprop=url&format=xml&ailimit=10&aifrom=jura
This returns an xml feed, from which i get the image names and url's:
<img name="Jura.PNG" url="http://upload.wikimedia.org/wikipedia/en/a/ad/Jura.PNG" descriptionurl="http://en.wikipedia.org/wiki/File:Jura.PNG"/>
Then, to get the information, such as uploader and license, i use this tool, as linked on wikimedia:
http://toolserver.org/~magnus/commonsapi.php
It requires the parameter ?image=
, followed by a filename. Jura.PNG
from the xml example, works fine. However, most other one's i try just return <error>File does not exist</error>
. I've tested, the files do exist. I can't figure out why one file works, and another doesn't.
For testing, another one that works is Calumma_tarzan_01.jpg
.
Does anyone know what i'm doing wrong?
Not working examples:
Jurassic.jpg
Juramento_de_la_Primera_Junta.jpg
JuraDolois_logo.jpg
Used php code:
$xml_link = "http://en.wikipedia.org/w/api.php?action=query&list=allimages&aiprop=url&format=xml&ailimit=10&aifrom=".$search_term;
$xml = simplexml_load_file( $xml_link );
$xml_link_data = "http://toolserver.org/~magnus/commonsapi.php?image=".$imgname;
$xml_data = simplexml_load_file( $xml_link_data );
var_dump($xml_data->licenses->license);
for the Jura.PNG
example the correct object is dumped, but since other urls dont have the license part, the result is obviously NULL
. I think the problem isn't here, however, since manual input of the url in a browser also won't return results.