I'm trying to learn Twitter API using LinqToTwitter. It works fine to connect to Twitter API but not Twitter Stream. As far as I can tell I need special rights to access the firehouse but the sample stream and the filter stream should be accessable. If that's true I can't seem to understand why I get "401 Unauthorized" with the following code:
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();
Twitter streams don't support application-only authorization. Try the SingleUserAuthorizer. Also, a 401 error can happen for several reasons and you can review the LINQ to Twitter FAQ for help.