Hello,
I have some problem with authentication while using Streaming API.
I am currently using following code for .NET.
string username = “twitter_Username”;
string password = “twitter_Password”;
string authHeader = “OAuth oauth_consumer_key=‘XXXXXXXXXXXXXXXXXXXXXX’, oauth_nonce=‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’, oauth_signature=‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’, oauth_signature_method=‘HMAC-SHA1’, oauth_timestamp=‘1373352690’, oauth_token=‘XXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’, oauth_version=‘1.0’”;
string parameters = “&track=twitter”;
Encoding encode = System.Text.Encoding.GetEncoding(“utf-8”);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(“https://stream.twitter.com/1.1/statuses/filter.json”);
webRequest.Credentials = new NetworkCredential(username, password);
webRequest.Timeout = -1;
webRequest.Method = “POST”;
webRequest.ContentType = “application/x-www-form-urlencoded”;
webRequest.Headers.Add(“Authorization”, authHeader);
byte[] _twitterTrack = encode.GetBytes(parameters);
webRequest.ContentLength = _twitterTrack.Length;
Stream _twitterPost = webRequest.GetRequestStream();
_twitterPost.Write(_twitterTrack, 0, _twitterTrack.Length);
_twitterPost.Close();
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
When I execute this code, I get “Error 401 Unauthorized”.
Can anyone help me to overcome with this problem?
Thank you.