首页 文章

当searchType为image时,Google自定义搜索API会返回0结果

提问于
浏览
3

我正在使用Google Custom Search API搜索图片 . 我请求图像时搜索结果始终为0 . 我正在关注以下链接中的文档:

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

根据文档,通过指定searchType = images,api只查找图像 .

这是我的网址的样子:

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,我会以网页的形式返回结果 . 这有什么不对?

1 回答

  • 3

    您的自定义搜索引擎可能禁用了图像搜索 . 如果禁用了searchType请求,CSE API将返回0结果 .

    您可以通过访问https://cse.google.com/cse/all,打开搜索引擎并将"Image Search"切换切换为ON来启用它 .

相关问题