我正在尝试按照此处所述进行应用程序 oauth:https ://dev.twitter.com/docs/api/1.1/post/oauth2/token
但我这样做的尝试导致 403(forbidden) 我正在尝试的 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();
关于我在这里做错了什么有什么建议吗?