Unauthorized 401 on https://stream.twitter.com/1.1/statuses/filter.json


I am getting 401 Unauthorized on only location filter. Track and other filters are working correctly. I am using OAuth1 authentication for requests.


What library are you using? Can you share a code sample demonstrating the problem?


I am using C# HttpClient.

using (var client = new HttpClient(new OAuth1MessageHandler(new HttpClientHandler(), "consumerKey", "consumerSecret", "Token", "TokenSecret")))

                client.BaseAddress = new Uri("https://stream.twitter.com/1.1/");
                //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    .Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
                client.Timeout = TimeSpan.FromMinutes(5);
                //var locations = HttpUtility.UrlEncode("locations=-122.75,36.8,-121.75,37.8");
                var request = new HttpRequestMessage(HttpMethod.Get, "statuses/filter.json?track=twitter&locations=-122.75,36.8,-121.75,37.8");

                var response = await client.SendAsync(request,HttpCompletionOption.ResponseHeadersRead);
                var stream = await response.Content.ReadAsStreamAsync();
                using (var reader = new StreamReader(stream))
                    while (!reader.EndOfStream)

I am unable to format code correctly. Oauth1 headers are being sent correctly. I am only getting unauthorized on Location filter.


I’ve just successfully tried:

twurl -t -H stream.twitter.com -A "Accept-encoding: none" -d "locations=-122.75,36.8,-121.75,37.8" -X POST "/1.1/statuses/filter.json"

So, I suspect that you may not be encoding your request correctly. Have you tried using any of the third party Twitter API client libraries for C# rather than trying to do this yourself?


I tried TweetInvi C# Library. Wasn’t able to get any data. Maybe its my account issue.