views:

129

answers:

1

So I'm trying to build a real time monitoring tool for twitter key words using tweet sharp. I'm using the search API to collect queries every 10-15 seconds. When I make the calls, I only want to collect tweets that have appeared since the pervious update.

var twitter = FluentTwitter.CreateRequest().AuthenticateAs("username", "password").Search().Query().Containing("key word").Take(1000);
var response = twitter.Request();

currentResponseDateTime= Convert.ToDateTime(response.ResponseDate);

var messages = from m in response.AsSearchResult().Statuses
               where m.CreatedDate > lastUpdateDateTime
               select m;

lastUpdateDateTime = currentResponseDateTime;

My issue is that the twitter server time is different from the client times by a few seconds. I looked around and tried to get the datetime I recieved the response from the Response.ResponseDate property, but it looks like that is set based on the local computer time. I.e currentResponseDateTime is a few seconds ahead of the Twitter Server time. So I end up not collecting a few of the tweets.

Does anyone know how I can get the current server time from twitter search or REST API?

Thanks

+3  A: 

I'm not sure how you would get the local server time of the twitter service, but one approach you could take is to store the date of the most recent twitter update seen in the "lastUpdateDateTime" field. That way, you're guaranteed to get all the messages since the last one you saw, regardless of the offset of the twitter server.

        var twitter = FluentTwitter.CreateRequest().AuthenticateAs("username", "password").Search().Query().Containing("key word").Take(1000);
        var response = twitter.Request();

        currentResponseDateTime= Convert.ToDateTime(response.ResponseDate);

        var messages = from m in response.AsSearchResult().Statuses
                       where m.CreatedDate > lastUpdateDateTime
                       select m;

        lastUpdateDateTime = messages.Select(m => m.CreatedDate).Max();
Ryan Brunner
The way I wanted to say it
Vestel
Thats a good idea. Thanks!
abudker

related questions