Return recent n number of tweets using TweetSharp
Asked Answered
W

1

12

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.

Walz answered 5/8, 2015 at 14:32 Comment(0)
B
5

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;
    }
}
Bashee answered 18/8, 2015 at 20:14 Comment(1)
Still more up-to-date than TweetSharp. Latest nuget package of Linq2Twitter is from feb 2016 so that's acceptable. There also seems to be a new fork of TweetSharp here that might be worth looking into.Bashee

© 2022 - 2024 — McMap. All rights reserved.