谷歌自定义搜索API在搜索类型为图像时返回0结果。

5

我正在使用谷歌自定义搜索API搜索图像。当我请求图像时,搜索结果总是为0。我正在按照下面链接中的文档进行操作:

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

根据文档,通过指定searchType=images,API只会寻找图片。
下面是我的URL样式:

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

结果如下所示:

    {
 "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"
 }
}

如果我从请求中删除searchType,那么我会收到以网页形式返回的结果。这里出了什么问题?
2个回答

7

您的定制搜索引擎可能已禁用图像搜索。如果搜索类型请求被禁用,则CSE API返回0个结果。

您可以通过访问https://cse.google.com/cse/all,打开您的搜索引擎,并将“图片搜索”开关切换到“开启”状态来启用它。


1
图像搜索目前已启用。 - Ahmed Mujtaba

4

我晚延迟了2年,但我找到了解决方案。 您需要进入自定义搜索引擎仪表板并打开“搜索整个Web”或类似的属性。 当您激活该属性时,您必须能够看到结果。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接