0
私は、oAuthトークンを取得するために残りのサービスを直接呼び出そうとC#からWindows Live SDKを使用していますが、代わりに401エラーが表示されます。無許可。Windows Live SDK認証
自分のアプリケーションをデスクトップアプリケーションとしてhttps://manage.dev.live.com/に登録して公開していますので、自分のクライアントIDと秘密鍵を持っています。
私のデスクトップアプリケーションからは、ライブログイン用のInternet Explorerウィンドウを開き、確認コードを取得します。そのコード、秘密鍵とのclientIdを持つ
私は、このようにAccessToken.aspxを呼び出す:
try
{
string requestUrl = "https://consent.live.com/AccessToken.aspx";
// Request the access token.
string postData = string.Format("wrap_client_id={0}&wrap_client_secret={1}&wrap_verification_code={2}",
clientId,
secretKey,
verificationCode);
postData = HttpUtility.UrlEncode(postData);
byte[] postDataEncoded = System.Text.Encoding.UTF8.GetBytes(postData);
WebRequest req = HttpWebRequest.Create(requestUrl);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = postDataEncoded.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(postDataEncoded, 0, postDataEncoded.Length);
WebResponse res = req.GetResponse();
string responseBody = null;
using (StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8))
{
responseBody = sr.ReadToEnd();
}
// Process FORM POST.
NameValueCollection responseCollection = System.Web.HttpUtility.ParseQueryString(responseBody);
return responseCollection["wrap_access_token"];
}
catch (Exception ex)
{
throw ex;
}
私が間違ってやっていますか?
ご協力いただきありがとうございます。