获取LinqToTwitter的推文

时间:2017-03-02 01:54:48

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

我试图从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帐户的帖子吗?比如公司账号还是庆祝账号?

1 个答案:

答案 0 :(得分:1)

LINQ to Twitter是异步的,所以你应该改变你的查询:

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

另外,在实例化auth后点击一个断点并检查Credentials以确保你已正确填充它们。

相关问题