【问题标题】:Exclude Retweets using LinqToTwitter使用 LinqToTwitter 排除转推
【发布时间】:2014-03-05 20:55:18
【问题描述】:

我的 LinqToTwitter 类不能排除转发。

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

search.IncludeRetweets==false没有选项。

如何使用它进行搜索?我应该尝试其他课程吗?

【问题讨论】:

    标签: twitter linq-to-twitter


    【解决方案1】:

    Twitter API 不提供该选项,因此 LINQ to Twitter 也不提供。也就是说,您可以执行以下操作:

    1. 正常执行您的搜索查询。它将包含转发。
    2. 使用设置 RetweetedStatus.StatusID == 0 条件的 where 子句对结果执行 LINQ to Objects 查询,如下所示:

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

    我之所以建议使用这样的 where 子句,是因为 LINQ to Twitter 为 RetweetedStatus 实例化了一个 Status,无论它是否存在。但是,该状态的内容是每个属性类型的默认值。因为对于有效的转推,StatusID 永远不会为 0,所以这是可行的。您还可以过滤另一个字段,例如 Text == null,它仍然可以工作。

    【讨论】:

    • 我不知道,推特不支持。谢谢。我会在搜索查询中尝试 -RT。
    【解决方案2】:

    只需在您的搜索词中添加exclude:replies 和/或exclude:retweets:

    term = term + " exclude:replies exclude:retweets";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-16
      • 2018-11-05
      • 2016-12-16
      • 1970-01-01
      • 2019-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多