1
我試圖爲概述這裏做應用程序的OAuth:https://dev.twitter.com/docs/api/1.1/post/oauth2/tokenTwitter應用程序的OAuth 403
,但我嘗試這樣做導致403(禁止)的C#代碼,我試圖爲:
String key = ConfigurationManager.AppSettings["TwitterConsumerKey"];
String secret = ConfigurationManager.AppSettings["TwitterConsumerSecret"];
String bearerCredentials = HttpUtility.UrlEncode(key) + ":" + HttpUtility.UrlEncode(secret);
bearerCredentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(bearerCredentials));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.twitter.com/oauth2/token");
request.Method = "POST";
request.Headers.Add("Authorization", "Basic " + bearerCredentials);
request.ContentType = "Content-Type: application/x-www-form-urlencoded;charset=UTF-8";
string postData = "grant_type=client_credentials";
byte[] data = System.Text.Encoding.UTF8.GetBytes(postData);
request.ContentLength = data.Length;
request.GetRequestStream().Write(data, 0, data.Length);
WebResponse response = request.GetResponse();
任何關於我在這裏做錯的建議?
太棒了!這幫了我很多。 –