Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return recent n number of tweets using TweetSharp

I am trying to get recent 200 tweets using TweetSharp but it is returning 12 for some reason.

var service = new TwitterService(
                 _consumerKey,
                 _consumerSecret,
                 tokenClaim,
                 tokenSecret
                 );

IAsyncResult result = service.BeginListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions { Count = 200}
IEnumerable<TwitterStatus> tweets = service.EndListTweetsOnUserTimeline(result);

Any ideas why would that be? Thanks

Update

Following How to fetch maximum 800 tweets from ListTweetOnHomeTimeline() method of TweetSharp?

 IAsyncResult result =
            _twitterService.BeginListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions { Count = 200 });
        IEnumerable<TwitterStatus> tweets = _twitterService.EndListTweetsOnUserTimeline(result).ToArray();

        var tweet2 = _twitterService.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions { Count = 200, MaxId = tweets.Last().Id });

        return tweet2;

tweet2 is empty.

like image 510
Chirdeep Tomar Avatar asked Aug 05 '15 14:08

Chirdeep Tomar


1 Answers

TweetSharp is an old library and no longer maintained. It is known to have authentication problems, but big chance is that you're bumping against an other issue due to Twitter API changes. Just don't waste your time trying to fix it.

I suggest you to use the more up-to-date library Linq2Twitter which is also available on NuGet.

With LinqToTwitter your code would look like:

static async Task<List<Status>> ListTweetsOnUserTimeline(string screenName)
{
    var auth = new SingleUserAuthorizer
    {
        CredentialStore = new SingleUserInMemoryCredentialStore
        {
            ConsumerKey = consumerKey,
            ConsumerSecret = consumerSecret,
            AccessToken = accessToken,
            AccessTokenSecret = accessTokenSecret
        }
    };

    using (var context = new TwitterContext(auth))
    {
        var tweets = await (from tweet in context.Status
                            where tweet.Type == StatusType.User &&
                                  tweet.Count == 200 &&
                                  tweet.ScreenName == screenName
                            select tweet)
                            .ToListAsync();
        return tweets;
    }
}
like image 77
huysentruitw Avatar answered Sep 22 '22 17:09

huysentruitw