I'm attempting to complete an app that I need to download images from Wikimedia Commons using their API, in a similar way to using their online search at https://commons.wikimedia.org/. Using their online search for "orange" shows a multitude of orange images which is what I want using their API which returns no images for "orange".
Some searches using the API result in what I want (eg. apple, steak, milk, pear, pumpkin, broccoli). Others result in no images being returned (eg. orange, potato, carrot) whereas their online search works fine for all of these searches.
Examples of requests I have made using their API are as follows:
apple
works fine:
https://commons.wikimedia.org/w/api.php?action=query&format=json&generator=images&prop=imageinfo&iiprop=url&titles=apple&gimlimit=48
Result from request body = {"batchcomplete":"","continue":{"gimcontinue":"54098|Cider_and_apple_juice.jpg","continue":"gimcontinue||"},"query":{"pages":{"44430987":{"pageid":44430987,"ns":6,"title":"File:(A bunch of Royal Gala Apples from Chile).JPG","imagerepository":"local","imageinfo":[{"url":"https://upload.wikimedia.org/wikipedia/commons/e/eb/%28A_bunch_of_Royal_Gala_Apples_from_Chile%29.JPG","descriptionurl":"https://commons.wikimedia.org/wiki/File:(A_bunch_of_Royal_Gala_Apples_from_Chile).JPG","descriptionshorturl":"https://commons.wikimedia.org/w/index.php?curid=44430987"}]},"37689295":{"pageid":37689295,"ns":6,"title":"File:2015 01 Appelpannenkoek.jpg"
, ...... etc.
orange
returns no images but works fine on their website.
https://commons.wikimedia.org/w/api.php?action=query&format=json&generator=images&prop=imageinfo&iiprop=url&titles=orange&gimlimit=48
Result from request body = {"batchcomplete":""}
What can I do to fix this issue?
Using
https://commons.wikimedia.org/w/api.php?action=query&format=json&generator=images&prop=imageinfo&iiprop=url&titles=apple&gimlimit=48
you're asking for all the images contained in the page https://commons.wikimedia.org/wiki/apple.
This cannot be done for oranges simply because the page https://commons.wikimedia.org/wiki/orange does not exist.
If you want to simulate the Wikimedia Commons search, you can use:
https://commons.wikimedia.org/w/api.php?action=query&generator=search&gsrsearch=orange&gsrnamespace=6&format=json