Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude Retweets using LinqToTwitter

My LinqToTwitter class can not exclude retweets.

var srch = (from search in twitterCtx.Search where search.Type == SearchType.Search && search.Query == term && search.Count == 100 select search).SingleOrDefault();

There is no option about search.IncludeRetweets==false.

How can I do a search with that? Should I try another class?

like image 541
Tayfun Yaşar Avatar asked Feb 22 '26 23:02

Tayfun Yaşar


1 Answers

The Twitter API doesn't offer that option, so neither does LINQ to Twitter. That said, here's what you can do:

  1. Perform your search query as normal. It will contain retweets.
  2. Perform a LINQ to Objects query on the results using a where clause that sets the condition of RetweetedStatus.StatusID == 0, like this:

    var nonRetweetedStatuses =
        (from tweet in searchResponse.Statuses
         where tweet.RetweetedStatus.StatusID == 0
         select tweet)
        .ToList();
    

The reason why I suggested using the where clause like this is because LINQ to Twitter instantiates a Status for RetweetedStatus, regardless of whether it exists or not. However, the contents of that Status are the default values of each properties type. Since StatusID will never be 0 for a valid retweet, this works. You could also filter on another field like Text == null and it would still work.

like image 111
Joe Mayo Avatar answered Feb 27 '26 10:02

Joe Mayo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!