Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google custom search api returns 0 results when searchType is image

I'm using Google Custom Search API to search for images. The search result is always 0 when I request for images. I'm following the documentation at the link below:

https://developers.google.com/custom-search/json-api/v1/reference/cse/list

according to the docs, by specifying searchType=images, the api only looks for images.

Here's what my url looks like:

https://www.googleapis.com/customsearch/v1?key=[API_Key]&cx=017576662512468239146:omuauf_lfve&searchType=image&q=cars

and the result looks like below:

    {
 "kind": "customsearch#search",
 "url": {
  "type": "application/json",
  "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
 },
 "queries": {
  "request": [
   {
    "title": "Google Custom Search - cars",
    "totalResults": "0",
    "searchTerms": "cars",
    "count": 10,
    "inputEncoding": "utf8",
    "outputEncoding": "utf8",
    "safe": "off",
    "cx": "017576662512468239146:omuauf_lfve",
    "searchType": "image"
   }
  ]
 },
 "searchInformation": {
  "searchTime": 0.049329,
  "formattedSearchTime": "0.05",
  "totalResults": "0",
  "formattedTotalResults": "0"
 }
}

If I remove searchType from the request, I get results back in the form of web pages. What is wrong here?

like image 820
Ahmed Mujtaba Avatar asked Feb 06 '23 18:02

Ahmed Mujtaba


2 Answers

Your Custom Search Engine might have Image Search disabled. The CSE API returns 0 results if the searchType requested is disabled.

You can enable it by visiting https://cse.google.com/cse/all, opening your search engine, and switching the "Image Search" toggle to ON.

like image 116
Hazerd Avatar answered Apr 28 '23 10:04

Hazerd


I'm 2 years delayed but i found the solution. you need to go at your Custom Search Engine Dashboard and turn on the property "Search the entire Web" Or something like that. When you get that property activated you must be able to see results

like image 32
Elliot Jose Pichardo Martinez Avatar answered Apr 28 '23 08:04

Elliot Jose Pichardo Martinez