How can I use the Twitter search API to return all tweets that match my search query posted in only the last five seconds?

I would like to use the API to return all tweets that match my search query, but only tweets posted in the last five seconds.

With the Twitter Search API, I can use the_id to grab all tweets from a specific ID. However, I cannot see a good way to find the tweet id to start with it.

I also know that you can use "starting from:" in the actual query to use the date, but you cannot enter the time.

Can anyone with the Twitter API API offer me any tips? Thanks for reading and your time!

http://apiwiki.twitter.com/Search-API-Documentation

+6
api search search-engine twitter
source share
5 answers

This is similar to what you can do on your part, as created_at is one of the fields returned in the result set. Just make your request and use only those that are in the last 5 seconds.

+4
source share
<script type="text/javascript" charset="utf-8"> // JavaScript Document $(document).ready(function(){ // start twitter API $.getJSON('http://twitter.com/status/user_timeline/YOUR_NAME.json?count=10&callback=?', function(data){ $.each(data, function(index, item){ $('#twitter').append('<div class="tweet"><p>' + item.text.linkify() + '</p><p><strong>' + relative_time(item.created_at) + '</strong></p></div>'); }); }); function relative_time(time_value) { var values = time_value.split(" "); time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3]; var parsed_date = Date.parse(time_value); var relative_to = (arguments.length > 1) ? arguments[1] : new Date(); var delta = parseInt((relative_to.getTime() - parsed_date) / 1000); delta = delta + (relative_to.getTimezoneOffset() * 60); var r = ''; if (delta < 60) { r = 'a minute ago'; } else if(delta < 120) { r = 'couple of minutes ago'; } else if(delta < (45*60)) { r = (parseInt(delta / 60)).toString() + ' minutes ago'; } else if(delta < (90*60)) { r = 'an hour ago'; } else if(delta < (24*60*60)) { r = '' + (parseInt(delta / 3600)).toString() + ' hours ago'; } else if(delta < (48*60*60)) { r = '1 day ago'; } else { r = (parseInt(delta / 86400)).toString() + ' days ago'; } return r; } String.prototype.linkify = function() { return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) { return m.link(m); }); };// end twitter API }); // ***** end functions ***** </script> <div id="twitter"> Target Div </div> 
+2
source share

Are you trying to try out tweets in real time? Twitter has no req / hour API restriction. I think you would hit quickly.

0
source share

Why don't you just call the API every 5 seconds and grab the top of the tweet.

0
source share

Twitter API results are sorted by default by default. Please view the following quote from the twitter wiki:

Twitter API search parameter:

result_type: Optional. Determines the type of search you prefer to receive.

 * Valid values include: o mixed: In a future release this will become the default value. Include both popular and real time results in the response. o recent: The current default value. Return only the most recent results in the response. o popular: Return only the most popular results in the response. * Example: http://search.twitter.com/search.atom?q=Twitter&result_type=mixed * Example: http://search.twitter.com/search.json?q=twitterapi&result_type=popular * Example: http://search.twitter.com/search.atom?q=justin+bieber&result_type=recent 

Please correct me if I'm wrong somewhere.

Thanks and respect,
Abhay Dandekar

0
source share

All Articles