this is my code:
public static void Streaming(string method, string hashAlgorithm, string url, string consumerKey, string consumerSecret, HttpSessionStateBase Session)
{
while (true)
{
try
{
url = OAuth.GetUrl(method, hashAlgorithm, url, consumerKey, consumerSecret);
var req = HttpWebRequest.Create(url);
if (method != null) req.Method = method;
List result = new List();
using (var response = req.GetResponse())
using (var stream = response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
while (true)
{
var line = reader.ReadLine();
result.Add(line);
Session.Remove(“Tweets”);
Session[“Tweets”] = result;
}
}
}
catch (Exception ex)
{
Session.Remove(“Tweets”);
Session[“Tweets”] = ex.Message;
Thread.Sleep(5000);
}
}
}
public static string GetUrl(string method, string hashAlgorithm, string url, string consumerKey, string consumerSecret)
{
method = method ?? “GET”;
hashAlgorithm = hashAlgorithm ?? HMACSHA1;
string timestamp = Math.Floor((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();
string nonce = GetRandomString(10);
int index = url.IndexOf('?');
string querystring;
if (index == -1) {
querystring = string.Empty;
} else {
querystring = url.Substring(index + 1);
url = url.Substring(0, index);
}
//parse the querystring into a dictionary, rather than NameValueCollection, so it's easier to manipulate
Dictionary<string, string> query = querystring.Split('&').Select(x => {
int i = x.IndexOf('=');
if (i == -1) return new[] { x, null };
else return new[] { x.Substring(0, i), Uri.UnescapeDataString(x.Substring(i + 1)) };
}).ToDictionary(x => x[0], y => y[1]);
//add the oauth stuffs
query.Add("oauth_consumer_key", consumerKey);
query.Add("include_entities", "true");
query.Add("oauth_nonce", nonce);
query.Add("oauth_signature_method", "HMAC-SHA1");
query.Add("oauth_timestamp", timestamp);
query.Add("oauth_token", "27111111-y97mIqoSxxxxixxxxxxxx");
query.Add("oauth_version", "1.0");
query.Add("track", "spc12");
//put the querystring back together in alphabetical order
querystring = string.Join("&", query.OrderBy(x => x.Key).Select(x => string.Concat(x.Key, (x.Value == null ? string.Empty : "=" + x.Value.UrlEncode()))).ToArray());
string data = string.Concat(method.ToUpper(), "&", url.UrlEncode(), "&", querystring.Substring(1).UrlEncode());
string sig;
using (var hasher = GetHashAglorithm(hashAlgorithm)) {
hasher.Key = (consumerSecret + "&NxxxxxxxxxxxxxwmAUfM").GetBytes();
sig = hasher.ComputeHash(data.GetBytes()).ToBase64();
}
return string.Concat(url, "?", querystring, "&oauth_signature=", sig.UrlEncode());
}