【发布时间】:2012-05-13 07:05:56
【问题描述】:
我的 Mac 最近“退役”了,所以我成功地将我的 Rails 2.3.8 应用程序移植到了 Windows 上的 Ubuntu 安装。一切正常,除了现在我使用 Google 自定义搜索 (CSE) 进行图像搜索时没有得到任何结果。
我有一个有效的 API 密钥和一个唯一的自定义搜索 ID - 这已得到确认,因为我在使用 CSE 执行常规“网络”搜索时得到了结果。我也在每日请求限制之内。我还仔细检查了 API 参考,以确保发布的语法没有改变,也没有改变。
我发出以下请求:
result_count=10
query='apple'
1) 网页搜索(产生结果) - - - - - - - - - - - - - - - - - - - - - - - - - - - -
type=''
url="https://www.googleapis.com/customsearch/v1?key=#{ENV['GOOGLE_KEY']}&cx=#{ENV['GOOGLE_SEARCH_ID']}#{type}&alt=json&num=#{result_count}&q=#{query}"
RESULT => 正如预期的那样,包含 10 个项目/结果的 JSON 格式字符串
2) 图片搜索(无论查询如何都没有结果) - - - - - - - - - - - - - - - -
type='&searchType=image'
url="https://www.googleapis.com/customsearch/v1?key=#{ENV['GOOGLE_KEY']}&cx=#{ENV['GOOGLE_SEARCH_ID']}#{type}&alt=json&num=#{result_count}&q=#{query}"
RESULT => 包含 0 个项目/结果的 JSON 格式字符串,如下所示:
{
"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 - apple",
"totalResults": "0",
"searchTerms": "apple",
"count": 10,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"cx": "my_private_cx_id",
"searchType": "image"
}
]
},
"searchInformation": {
"searchTime": 0.023136,
"formattedSearchTime": "0.02",
"totalResults": "0",
"formattedTotalResults": "0"
}
}
在我移植应用程序之前,图像搜索一直有效 - 我不知道我错过了什么,但我怀疑这是一个小疏忽。
【问题讨论】:
标签: ruby-on-rails google-search-api