Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google custom search for images only

Tags:

Since Google image search API is deprecated, one should use Google custom search API for this.

I've made a small example using it. My problem is I want to return google image search results only. Whereby this shows web results, and the user may switch to the image result. How can I show only the image results by default?

<div id="cse" style="width: 100%;">Loading</div> <script src="http://www.google.com/jsapi" type="text/javascript"></script> <script type="text/javascript">   google.load('search', '1', {language : 'hu'});   google.setOnLoadCallback(function() {     var customSearchOptions = {         enableImageSearch: true,         imageSearchOptions: {               layout: google.search.ImageSearch.LAYOUT_CLASSIC         }     };      var options = new google.search.DrawOptions();     options.setAutoComplete(true);      var customSearchControl = new google.search.CustomSearchControl('XXX', customSearchOptions);      customSearchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);     customSearchControl.setAutoCompletionId('XXX');      customSearchControl.draw('cse', options);   }, true); </script> <link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" /> 

The API documentation is quite poor, it only describes how to add additional results.

like image 419
sibidiba Avatar asked Dec 09 '11 16:12

sibidiba


People also ask

How do I customize Google Custom Search?

From the Programmable Search Engine homepage, click Create a custom search engine or New search engine. In the Sites to search box, type one or more sites you want to include in the search results. You can include any sites on the web, even sites you don't own. Don't worry, you can always add more later.

How do I enable Google image search?

On the Custom Search home page, click the search engine you want. Click Setup, and then click the Basics tab. In the Image search section, switch image search to ON.

What happened to Google image search?

The change comes as part of a settlement with Getty Images that aims to improve attribution for their contributors, Google said. The search engine also removed its “search by image” button, but users can still reverse image search by dragging images to the Google search bar.


1 Answers

Google images search is now supported in the Custom Search Engine API. See the API parameters section of this page. I'm using the API with python and for my application I just specify the parameter in the API call.

searchType = "image" 

See this post on the cse blog.

EDIT: As Marc points out in his comment below, you need to click "Enable image search" in your CSE console.

like image 165
kelorek Avatar answered Nov 14 '22 05:11

kelorek