Created
March 2, 2020 15:52
-
-
Save reuniware/a5d1cb0d457584650c6a1c8531c23bf6 to your computer and use it in GitHub Desktop.
twitter api test (ko for now)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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