Wikimedia API get generator metadata

2019-09-08 14:48发布

问题:

I want to get pages from Wikimedia Commons and it seems, that I have still not understand the usage of the Wikimedia API.

I use the following query

https://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&format=json&iiprop=url|size|mime|mediatype|extmetadata&iiurlwidth=150&generator=search&gsrsearch=transformation&gsrnamespace=6&gsrlimit=9&gsroffset=0&gsrinfo=totalhits

See in API Sandbox

Which works great, except that I don't get the grsinfo / generator metadata. But I need the total amount of results (totalhits).

Any suggestions?

回答1:

Per the docs,

It should also be noted that generators only pass page titles to the 'real' query, and do not output any information themselves. Setting parameters like gcmprop will therefore have no effect.

If you need the hit count, you'll have to do a normal search API query, manually generate a list of pages from it and query them in a second API request.