2012-03-30 101 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