javascriptwikipedia-apiwikimedia

How to query wikimedia commons images with descriptions?


I'm trying to build a gallery of sorts so that my user can search for images on various topics that are in the public domain. I'm trying to pull down a list of images from wikimedia but with their descriptions or "alt" descriptions. I can't figure out from the docs how to do that. Here's the api url I've managed to piece together so far from research. For example all images of "Lewis Hayden":

action=query&prop=imageinfo|categories&generator=search&gsrsearch="Lewis Hayden"&origin=*

From this I get the url from which I can then build an tag for the images. But I can't get the description or the title of the picture. Is there a better way to do this?


Solution

  • Try something like

    action=query&prop=imageinfo|categories&generator=search&gsrsearch=File:Lewis&iiprop=extmetadata&iiextmetadatafilter=ImageDescription|ObjectName

    The File: search keyword will make it search images instead of pages; iiprop=extmetadata will expose image metadata (like description).