2012-03-30 102 views
0

我的Mac最近“退役”,因此我成功地将我的Rails 2.3.8应用程序移植到了Windows上的Ubuntu安装。除了现在当我使用我的Google自定义搜索(CSE)进行图片搜索时,我没有得到任何结果,一切运作良好。图像搜索没有结果

我有一个有效的API密钥和一个唯一的自定义搜索ID - 这是确认的,因为我在使用CSE执行常规“web”搜索时得到了结果。我也处于每日要求限制范围内。我还仔细检查了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 =>如所预期的,一个JSON格式字符串10项/导致

2)图像搜索(NO的结果,无论ö ˚F查询) - - - - - - - - - - - - - - - - -

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 =>的JSON格式字符串与0商品/结果,如下所示:

{ 
"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" 
} 
} 

图像搜索曾用于工作,直到我移植的应用程序 - 我不知道我失踪,但我怀疑这是一个小的疏忽。

回答

2

我认为这可能是由于您尚未启用自定义搜索引擎的图像搜索。你可以在CSE的控制台下启用该功能。

+0

好东西。谢谢Redan - 我错过了那个。现在都在工作。干杯。 – frank 2012-04-23 17:01:48