2016-11-07 61 views
2

我正在使用Google自定义搜索API搜索图片。当我请求图像时,搜索结果始终为0。我下面的文档在下面的链接:根据文档当searchType为图片时,Google自定义搜索api返回0结果

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

,通过指定检索类别=图像,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" 
} 
} 

如果我从请求删除检索类别,我得到的结果返回的形式网页。这里有什么问题?

回答

1

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

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

+0

图片搜索当前已启用 –

相关问题