通过 LinqToTwitter 获取推文
Get Tweets by LinqToTwitter
我正在尝试从 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 帐户的帖子?喜欢公司帐户还是庆祝帐户?
LINQ to Twitter 是异步的,因此您应该像这样更改您的查询:
var tweets =
await
(from tw in context.Status
where
tw.Type == StatusType.User &&
tw.ScreenName == "***"
select tw)
.ToListAsync();
此外,在实例化 auth 后打断点并检查凭据以确保您已正确填充它们。
我正在尝试从 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 帐户的帖子?喜欢公司帐户还是庆祝帐户?
LINQ to Twitter 是异步的,因此您应该像这样更改您的查询:
var tweets =
await
(from tw in context.Status
where
tw.Type == StatusType.User &&
tw.ScreenName == "***"
select tw)
.ToListAsync();
此外,在实例化 auth 后打断点并检查凭据以确保您已正确填充它们。