3

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?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Tayfun Yaşar
  • 422
  • 2
  • 9
  • 24

2 Answers2

6

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.

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
2

Just add to your search term exclude:replies and/or exclude:retweets:

term = term + " exclude:replies exclude:retweets";
Shrike
  • 9,218
  • 7
  • 68
  • 105