I have built a Twitter library for getting data from twitter apis. The REST APIs are working fine. I am getting a 401 unauthorized error for Public Streams by location. Here are the error details:
Transfer-Encoding: chunked
Cache-Control: must-revalidate,no-cache,no-store
Content-Type: text/html
WWW-Authenticate: OAuth realm=“Firehose”
The api I am accessing is : https://stream.twitter.com/1.1/statuses/filter.json?locations=34.54899790,16.3795280,55.66669990,32.1542840
Here is my code:
Uri = https://stream.twitter.com/1.1/statuses/filter.json?locations=34.54899790,16.3795280,55.66669990,32.1542840
System.Uri APIUrl = new System.Uri(Uri);
//The Header builder generates the signature as well.
UriHeader = APIHelper.RequestHeaderBuilder(Credentials, APIUrl);
//Generate Web Request & Request Header
HttpWebRequest webRequest = null;
webRequest = (HttpWebRequest)System.Net.WebRequest.Create(APIUrl);
webRequest.Method = "GET";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Headers.Add("Authorization", UriHeader);
webRequest.Host = "stream.twitter.com";
HttpWebResponse TwitterResponse = (HttpWebResponse)webRequest.GetResponse();
using (StreamReader reader = new StreamReader(TwitterResponse.GetResponseStream()))
{
while (true)
{
var line = reader.ReadLine();
if (String.IsNullOrEmpty(line)) continue;
dynamic obj = JsonConvert.DeserializeObject(line);
if (obj.user != null)
Console.WriteLine(obj.user.screen_name + ": " + obj.text);
}
}
The signature is working fine for other APIs. Can you please tell me if I am missing something.