Image results now available from the Custom Search API
February 14th, 2012 | Published in Google Code
By Nam Nguyen, Software Engineer
Last year we added image results to Google Custom Search Engines to enable sites to offer image-only results that showcase photos and other digital images. For site owners who want more flexibility in presentation, they are also now available from the Custom Search API.
Read more about accessing Image Results from the Custom Search API or try it out in the Custom Search API Explorer. For billing purposes, image queries will be treated the same as web queries. If you are still using the deprecated Google Image Search API, now’s a great time to switch!
Below is an example of an image search to find small jpeg images of flowers:
https://www.googleapis.com/customsearch/v1?key=YOUR_API_KEY&cx=YOUR_CSE_ID&q=flower&searchType=image&fileType=jpg&imgSize=small&alt=json
With a valid key and cse id, here is a possible json result returned for an image item:
{
"kind": "customsearch#result",
"title": "flower-photo",
"htmlTitle": "\u003cb\u003eflower\u003c/b\u003e-photo",
"link": "http://images.example.com/flowerphoto.jpg",
"displayLink": "images.example.com",
"snippet": "photo of flower",
"htmlSnippet": "photo of \u003cb\u003eflower\u003c/b\u003e",
"mime": "image/jpeg",
"image": {
"contextLink": "http://images.example.com/flowergallery.html",
"height": 100,
"width": 100,
"byteSize": 6104,
"thumbnailLink": "https://encrypted-tbn2.google.com/images?q=tbn:3x4MPL3",
"thumbnailHeight": 82,
"thumbnailWidth": 82
}
}
which you can use to render the image in your own site.
Note that you need to enable image search in your custom search engine control panel for the custom image search to work.
Nam Nguyen works on the JSON/Atom Custom Search API, which lets developers retrieve and display results from Google Custom Search programmatically. He is dedicated to making developers' lives a little easier by providing a simple API.
Posted by Scott Knaster, Editor