以下のコードをC#言語で使用してアクセストークンを取得しようとしていますが、400の不正なリクエストの例外が発生しています。
コード:
WebRequest httpWReq = WebRequest.Create("https://www.box.com/api/oauth2/token");
string postData = "grant_type=authorization_code";
postData += "&code=" + Code;
postData += "&client_id=MY_CLIENT_ID";
postData += "&client_secret=MY_CLIENT_SECRET";
postData += "&redirect_uri=https://www.google.com";
byte[] data = Encoding.UTF8.GetBytes(postData);
httpWReq.Method = "POST";
httpWReq.ContentType = "application/x-www-form-urlencoding";
httpWReq.ContentLength = data.Length;
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = httpWReq.GetResponse();
var responseStream = response.GetResponseStream();
using (var reader = new StreamReader(responseStream))
{
var responseReader = reader.ReadToEnd();
MessageBox.Show(responseReader);
}
しかし、私は常に次のエラーを受け取ります:
{"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"}
この問題を克服する方法は?
どんな助けでもありがたいです。前もって感謝します。
ありがとう、ハリッシュ・レディ