2011-07-25 176 views
3

是否有任何方式向Twitter發送查詢參數,告訴它只在指定的時間段內返回搜索結果?例如,在2011年7月24日美國東部時間下午12點至下午3點之間發送此「關鍵字」的結果,請提供結果?如果Twitter不允許您按時間搜索 - 並且只能按日期搜索 - 那麼結果中是否有任何內容可以讓您查看用戶發佈推文的確切時間?Twitter搜索API - 按時間搜索

回答

2

據我所知,有不是一種方式來指定時間(比日期更具體)。但是,在獲取推文列表後,您可以通過比較每條推文的時間戳來移除那些不在指定時間範圍內的推文。

這是我將如何與twitter寶石做的紅寶石:

require 'twitter' 
require 'time' 

start_time = Time.now - 3*3600 
end_time = Time.now 

search = Twitter::Search.new.contains('test') 
search.since_date(start_time.strftime("%Y-%m-%d")) 
search.until_date(end_time.strftime("%Y-%m-%d")) 

tweets = search.fetch 

tweets.delete_if { |t| Time.parse(t.created_at) < start_time } 
tweets.delete_if { |t| Time.parse(t.created_at) > end_time }