Skip to content

Instantly share code, notes, and snippets.

@reuniware
Created March 2, 2020 15:52
Show Gist options
  • Select an option

  • Save reuniware/a5d1cb0d457584650c6a1c8531c23bf6 to your computer and use it in GitHub Desktop.

Select an option

Save reuniware/a5d1cb0d457584650c6a1c8531c23bf6 to your computer and use it in GitHub Desktop.
twitter api test (ko for now)
private string ConsumerKey = "lEmrWQ24XXXXXXXXXXDOGMFTT";
private string ConsumerSecret = "0soZwdgLq2s0AXXXXXXXXXXXXXXXXXXXXrN8UDq8zZbftLGPY0";
private void button1_Click(object sender, EventArgs e)
{
string strBearerRequest = HttpUtility.UrlEncode(this.ConsumerKey) + ":" + HttpUtility.UrlEncode(this.ConsumerSecret);
strBearerRequest = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(strBearerRequest));
HttpWebRequest req = WebRequest.Create("https://api.twitter.com/oauth2/token") as HttpWebRequest;
req.Method = "POST";
req.UserAgent = "IchimokuTrader77";
req.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
req.Headers.Add("Authorization", "Basic " + strBearerRequest);
//req.Headers[HttpRequestHeader.AcceptEncoding] = "gzip";
var reqBody = Encoding.UTF8.GetBytes("grant_type=client_credentials");
req.ContentLength = reqBody.Length;
Stream r = req.GetRequestStream();
r.Write(reqBody, 0, reqBody.Length);
r.Close();
string respBody = "";
using (var resp = req.GetResponse().GetResponseStream())
{
var respR = new StreamReader(resp);
respBody = respR.ReadToEnd();
}
textBox1.Text = respBody;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment