Reputation: 17512
Is there any way to send a query param to Twitter, telling it to only return search results within a specified period of time? For example, give me the results for this "keyword" tweeted between 12 pm and 3 pm ET on July 24, 2011? If Twitter doesn't allow you to search by time -- and only by date -- then is there anything in the results that will allow you to see the exact time when the user made that tweet?
Upvotes: 3
Views: 2962
Reputation: 194
As far as I can tell, there is not a way to specify time (more specific than the date). However, after getting your list of tweets, you can remove those that don't fall within the specified time range by comparing each tweet's timestamp.
This is how I would do it in ruby with the twitter
gem:
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 }
Upvotes: 2