问题描述
由于已弃用,因此应使用。
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" />
API文档非常差,它只描述了如何添加其他结果。
The API documentation is quite poor, it only describes how to add additional results.
推荐答案
自定义搜索引擎API现在支持Google图片搜索。请参阅的API参数部分。我正在使用带有python的API,对于我的应用程序,我只是在API调用中指定参数。
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"
参见。
编辑:正如Marc在评论中指出的那样在下面,您需要在CSE控制台中单击启用图像搜索。
As Marc points out in his comment below, you need to click "Enable image search" in your CSE console.
这篇关于Google自定义搜索图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!