我正在尝试使用 LinqToTwitter 学习 Twitter API。它可以很好地连接到 Twitter API,但不能连接到 Twitter Stream。据我所知,我需要特殊权限才能访问消防站,但应该可以访问样本流和过滤器流。如果这是真的,我似乎无法理解为什么使用以下代码得到“401 Unauthorized”:
var auth = new ApplicationOnlyAuthorizer
{
Credentials = new InMemoryCredentials
{
ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
}
};
auth.Authorize();
var twitterCtx = new TwitterContext(auth);
int count = 0;
string response = "";
(from strm in twitterCtx.Streaming
where strm.Type == StreamingType.Filter &&
strm.Track == query
select strm)
.StreamingCallback(strm =>
{
if (strm.Status != TwitterErrorStatus.Success)
{
Console.WriteLine(strm.Error.ToString());
return;
}
response += "<p>" + strm.Content + "</p>";
if (count++ >= 2)
{
strm.CloseStream();
}
})
.SingleOrDefault();