I use twitter api and asp.net mvc 3 to search tweets by hashtag, I use this code
string codes = "XXXXXXXX";
byte[] arrCodes = System.Text.Encoding.Unicode.GetBytes(codes);
string base64Codes = Convert.ToBase64String(arrCodes);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
var webRequest = (HttpWebRequest)WebRequest.Create(@"https://api.twitter.com/oauth2/token");
webRequest.Method = "Post";
// webRequest.Host = "api.twitter.com";
webRequest.UserAgent = "NewProjapi";
webRequest.Headers.Add("Authorization: Basic "+base64Codes);
webRequest.Headers.Add("Accept-Encoding: gzip");
string postString = string.Format("grant_type=client_credentials");
byte[] postStringBytes = System.Text.Encoding.ASCII.GetBytes(postString);
webRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
webRequest.ContentLength = postStringBytes.Length;
Stream requestStream = webRequest.GetRequestStream();
requestStream.Write(postStringBytes, 0, postStringBytes.Length);
var webResponse = webRequest.GetResponse();
byte[] res = new byte[webResponse.ContentLength];
webResponse.GetResponseStream().Read(res, 0, res.Length);
but in line var webResponse = webRequest.GetResponse();, it said that The remote server returned an error: (500) Internal Server Error. I change my code and use Webclient but it still say that. Twitter support tells we resolve this problem but I have it still.
Online demo : http://onlinelab.somee.com/