Google Custom Search API for image searches

I have followed this guide and this reference to create a Custom Search Engine.

I've created it just to get image URLs from Google to use in my application.

However, when I test it out with a really common query (eg, q=heinz+baked+beans ), the results are nothing like the results you get when you perform the same search in Google Images (or Google).

Here is the API URL I am using:

SEARCH_URL_BASE = "https://www.googleapis.com/customsearch/v1" +
                "?key=PRIVATE" +
                "&cx=PRIVATE" + 
                "&cr=countryUK" +
                //"&exactTerms=heinz+baked+beans" +
                "&gl=uk" +
                "&googlehost=google.co.uk" +
                "&imgSize=medium" +
                "&imgType=photo" +
                "&safe=high" +
                "&searchType=image&fileType=jpg" +
                "&q=heinz+baked+beans"; //append the query

When you try this search manually in a browser, the top result (in both images.google.co.uk and google.co.uk) is from heinz.co.uk, but when I do the query through the API, that result is nowhere to be seen.

I have tried adding heinz.co.uk to the Sites to search field in my Custom Search Setup screen, which yielded 403 responses from the API, so I reverted it back to having no Sites to search (with Search the entire web... selected), but I'm still getting a 403 error.

Any ideas?


I have created a new google account (using a brand new email address - with, therefore, no search history in order to try and overcome Google's personalization 'feature') and have created a new key and custom search engine with it. This may have made the results less customised - but I am still experimenting with this.

However, I am still getting 403 responses for this new setup, and the only cause I can think of is that I was firing off my requests too quickly. My application was sleeping for 1000ms between each request, but it seems like this is not enough (even though I was well under the 1,000 requests that I'm allowed per day). I will try gradually increasing this sleep interval and will update this answer with the optimum sleep interval that is required between requests.

链接地址: http://www.djcxy.com/p/83798.html

上一篇: 使用Google自定义搜索API获取Google图片中的图片网址?

下一篇: Google自定义搜索API用于图片搜索