我的目标是能够访问用户的OneDrive文件夹。
首先,我将它们发送到此URL:
https://login.live.com/oauth20_authorize.srf?client_id={HIDDENFORSTACKOVERFLOW}&scope=onedrive.readwrite%20offline_access&response_type=code&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf
点击“是”后,我抓住令牌(例如:M14ae0635-f6a6-4ebb-1238-f7ab76936e2
)。
var request = (HttpWebRequest)WebRequest.Create("https://login.microsoftonline.com/common/oauth2/v2.0/token");
var postData = "&client_id={HIDDENFORSTACKOVERFLOW}";
postData += "&scope=onedrive.readwrite%20offline_access";
postData += string.Format("&code={0}", code);
postData += "&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf";
postData += "&grant_type=authorization_code";
postData += "&client_secret=rvuajDJVV79215{?|jpNID]";
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
我每次收到的都是错误400.请求不好。我尝试了似乎所有的东西。思考?