Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

With Twitter's Search API, I can use the since_id to grab all tweets from a specific ID. However, I can't really see a good way to find the tweet ID to begin from.

I'm also aware that you can use "since:" in the actual query to use a date, but you cannot enter a time.

Can someone with Twitter API experience offer me any advice? Thanks for reading and your time!

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

like image 816
rmh Avatar asked Oct 15 '08 19:10

rmh


People also ask

How far back can Twitter API Go?

30-Day Search API provides data from the previous 30 days. Full-Archive Search API provides complete and instant access to the full corpus of Twitter data dating all the way back to the first Tweet in March 2006.

How do I get more Twitter search results?

Click Advanced search, located underneath Search filters on the upper right of your results page, or click More options and then click Advanced search. Fill in the appropriate fields to refine your search results (see below for some helpful tips). Click Search to see your results.

Can you get old Tweets from Twitter API?

The Twitter API always gives you Tweets from the newest date to the oldest. You can either upgrade to the first tier and let it run as far as it goes or you start with a sample and guesstimate from there how many Tweets there are.


2 Answers

This sounds like something you can do on your end, as created_at is one of the fields returned in the result set. Just do your query, and only use the ones that are within the last 5 seconds.

like image 196
PJ Davis Avatar answered Oct 23 '22 05:10

PJ Davis


        <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>
like image 29
Dustin Avatar answered Oct 23 '22 04:10

Dustin