当searchType为image时,Google自定义搜索API返回0个结果 [英] Google custom search api returns 0 results when searchType is image

查看:60
本文介绍了当searchType为image时,Google自定义搜索API返回0个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google自定义搜索API搜索图像.当我请求图像时,搜索结果始终为0.我正在下面的链接中关注文档:

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

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

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

这是我的网址的样子:

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

,结果如下:

    {
 "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,我将以网页形式返回结果.怎么了?

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

推荐答案

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

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

您可以通过访问 https://cse.google.com/cse/all,打开您的搜索引擎,然后将图片搜索"切换到打开".

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

这篇关于当searchType为image时,Google自定义搜索API返回0个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆