3

I'm beginner to TweetSharp and I'm using the ListTweetsOnHomeTimeline() method of TweetSharp , sometimes this method works fine and sometimes its return null.

Below is my code

IEnumerable<TwitterStatus> homeTweets = service.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions());
            if (homeTweets != null)
            {
                foreach (var item in tweets)
                {
                    Console.WriteLine("{0} says '{1}'", item.User.ScreenName, item.Text);
                }
            }

Any help will be appreciated.

Pravesh Singh
  • 314
  • 1
  • 8
  • 27
  • What you are trying to do is as easy as anything but since you said you a beginner you can check out my response here [http://stackoverflow.com/questions/14303710/how-to-customize-twitter-widget-style/18634950#18634950] on how to customize twitter widgets .And if you follow the link you will find how twitter Api is customized . – ShapCyber Sep 05 '13 at 15:02

2 Answers2

3

I had the same problem because I was passing SinceId=0 as option (=null works fine); As I suppose you have modified your actual code before posting, this might be your problem. Or another invalid option that the Twitter API doesn't like.

Here is the piece of code that works for me:

//Persist lastMessageIdProcessed accross calls to prevent
//processing the same messages again and again
long? lastMessageIdProcessed=null;
IEnumerable<TwitterStatus> tweets=service.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions {
    SinceId=lastMessageIdProcessed>0?lastMessageIdProcessed:null,
    Count=100
});

if(tweets!=null)  //Shouldn't happen
{
    foreach(TwitterStatus tweet in tweets)
    {
        lastMessageIdProcessed=tweet.Id;
        //Do your stuff here
    }
}
Vincent
  • 938
  • 13
  • 20
  • Can you tell me what `lastMessageIdProcessed` is and how/where it's defined? – Robert Feb 20 '14 at 15:31
  • Sorry, I should have indicated this. `lastMessageIdProcessed` is the last value of `tweet.Id` that you processed, to prevent processing the same messages again and again. You probably want to persist this value in your database or so. – Vincent Feb 21 '14 at 03:01
1

I tried passing SinceId = null and it solved me the problem, like so:

IEnumerable<TwitterStatus> _tweets = _twitterService.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions { SinceId = null });

But only for a little while. I noticed that this is recurring, every now and then the request returns null, but if I try later, it works. I'm guessing there is a request limit.

I've found this: https://dev.twitter.com/docs/rate-limiting/1.1

Schrödinger's Box
  • 3,218
  • 1
  • 30
  • 51