TweetSharp method ListTweetsOnHomeTimeline() returns null

1.3k Views Asked by At

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.

2

There are 2 best solutions below

0
On

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

2
On

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
    }
}