问题
I'm looking for a way to specify that the images returned by the Google Custom Search API have a square format.
I've tried tbs=iar:s (because I've read Using the Custom Search API (REST JSON) to search for square images), but it doesn't work.
Have you an idea please ?
回答1:
The problem is that tbs
query parameter only applies to a regular image search on Google. For example, if you wanted to search for cat pictures with a square aspect ratio, you could do a search like this:
http://images.google.com/?q=cat&tbs=iar:s
But the Custom Search API uses a completely different set of parameters. The full list of supported parameters is shown in the REST documentation.
Some of the tbs queries do have equivalents. For example:
tbs=ic:gray
translates toimgColorType=gray
tbs=isz:m
translates toimgSize=medium
tbs=itp:clipart
translates toimgType=clipart
But sadly there appears to be no equivalent for the iar
aspect ratio filter. I tried guessing a few queries (things like imgAspectRatio=square
) in case there was an undocumented parameter, but didn't have any luck with that.
The best alternative I could suggest is using imgSize=icon
. This tends to return images that have a square aspect ratio, but with the unfortunate side effect that the images also tend to be rather small (the largest size I've seen returned is 256x256). Depending on your needs though, this may be good enough.
I apologise if this isn't particularly useful to you. I'm not just trying to grab the bounty on this question, so feel free not to vote this answer up. I just wanted to let you know what I had found in case it was of some help.
来源:https://stackoverflow.com/questions/16770726/google-custom-search-api-for-square-images