Ahm*_*aba 4 google-custom-search
我正在使用 Google 自定义搜索 API 来搜索图像。当我请求图像时,搜索结果始终为 0。我正在关注以下链接中的文档:
https://developers.google.com/custom-search/json-api/v1/reference/cse/list
根据文档,通过指定 searchType=images,api 只查找图像。
这是我的网址的样子:
结果如下所示:
{
"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"
}
}
Run Code Online (Sandbox Code Playgroud)
如果我从请求中删除 searchType,我会以网页的形式返回结果。这里有什么问题?
您的自定义搜索引擎可能禁用了图像搜索。如果所请求的 searchType 被禁用,CSE API 将返回 0 个结果。
您可以通过访问https://cse.google.com/cse/all来启用它,打开您的搜索引擎,然后将“图片搜索”切换为 ON。
归档时间: |
|
查看次数: |
3991 次 |
最近记录: |