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


#1

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


#2

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


#3

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.Clear();
                //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Accept
                    .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)
                    {
                        Console.WriteLine(reader.ReadLine());
                    }
                }
            }

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


#4

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?


#5

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