【问题标题】:Get Tweets by LinqToTwitter通过 LinqToTwitter 获取推文
【发布时间】:2017-07-21 14:10:13
【问题描述】:

我正在尝试从 Twitter 获取推文,但它对我不起作用,这是代码:

var auth = new SingleUserAuthorizer
            {

                CredentialStore = new SingleUserInMemoryCredentialStore()
                {

                    ConsumerKey = ConfigurationManager.AppSettings["***"],
                    ConsumerSecret = ConfigurationManager.AppSettings["***"],
                    AccessToken = ConfigurationManager.AppSettings["***"],
                    AccessTokenSecret = ConfigurationManager.AppSettings["***"]

                }

            };

var context = new TwitterContext(auth);
var tweets =
    from tw in context.Status
    where
        tw.Type == StatusType.User &&
        tw.ScreenName == "***"
    select tw;
// handle exceptions, twitter service might be down
try
{
    // map to list
    tweets
        .Take(3)
        .Select(t =>
            new Tweets
            {
                //Username = t.ScreenName,
                //FullName = t.User.Name,
                TweetText = t.Text,
                //FormattedText = ParseTweet(t.Text)
            })
        .ToList();
}
catch (Exception) { }

每次我尝试阅读推文时失败,例外是

LinqToTwitter.TwitterQueryException: Bad Authentication data

但我确信凭据是正确的。

还有可能阅读另一个 Twitter 帐户的帖子吗?比如公司帐户或庆祝帐户?

【问题讨论】:

    标签: c# twitter twitter-oauth linq-to-twitter


    【解决方案1】:

    LINQ to Twitter 是异步的,因此您应该像这样更改您的查询:

    var tweets =
        await
        (from tw in context.Status
         where
            tw.Type == StatusType.User &&
         tw.ScreenName == "***"
         select tw)
        .ToListAsync();
    

    另外,在实例化 auth 后打断点并检查凭据以确保您已正确填充它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 2016-04-28
      • 2014-12-19
      • 2017-08-20
      • 1970-01-01
      • 2012-07-14
      • 2011-08-04
      相关资源
      最近更新 更多