使用 Office 365 创建新活动 API
Create new events with Office 365 API
我得到了Error 401 Not Authorized
:
我已经配置好了所有的东西,下面的代码是运行通过按钮:
//Karim
string postData = "{\"Subject\": \"Discuss the Calendar REST API\",\"Body\": {\"ContentType\": \"HTML\",\"Content\": \"I think it will meet our requirements!\"},\"Start\": {\"DateTime\": \"2016 - 02 - 02T18: 00:00\",\"TimeZone\": \"Pacific Standard Time\"},\"End\": {\"DateTime\": \"2016 - 02 - 02T19: 00:00\",\"TimeZone\": \"Pacific Standard Time\"}}";
string Url = "https://outlook.office.com/api/v2.0/me/events";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(Url);
myHttpWebRequest.Method = "POST";
byte[] data = Encoding.ASCII.GetBytes(postData);
myHttpWebRequest.ContentType = "application/json";
myHttpWebRequest.Accept = "application/json";
myHttpWebRequest.ContentLength = data.Length;
Stream requestStream = myHttpWebRequest.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream responseStream = myHttpWebResponse.GetResponseStream();
StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default);
this.Label1.Text = myStreamReader.ReadToEnd();
myStreamReader.Close();
responseStream.Close();
myHttpWebResponse.Close();
//End Karim
我已经配置了 Office 365 开发人员工具,NuGet,我正在使用 Visual Studio 2015。
请求必须经过身份验证和授权才能请求这些 API。事实上,如果您不提供您代表谁提出此类请求的任何信息,谁会是“/我”?
为此,您应该设置一个所谓的身份验证承载,在您的 C# .NET 调用中,它看起来像这样
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "<your access token as string here>");
要了解如何检索此类访问令牌,请从 this documentation 开始。
我得到了Error 401 Not Authorized
:
我已经配置好了所有的东西,下面的代码是运行通过按钮:
//Karim
string postData = "{\"Subject\": \"Discuss the Calendar REST API\",\"Body\": {\"ContentType\": \"HTML\",\"Content\": \"I think it will meet our requirements!\"},\"Start\": {\"DateTime\": \"2016 - 02 - 02T18: 00:00\",\"TimeZone\": \"Pacific Standard Time\"},\"End\": {\"DateTime\": \"2016 - 02 - 02T19: 00:00\",\"TimeZone\": \"Pacific Standard Time\"}}";
string Url = "https://outlook.office.com/api/v2.0/me/events";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(Url);
myHttpWebRequest.Method = "POST";
byte[] data = Encoding.ASCII.GetBytes(postData);
myHttpWebRequest.ContentType = "application/json";
myHttpWebRequest.Accept = "application/json";
myHttpWebRequest.ContentLength = data.Length;
Stream requestStream = myHttpWebRequest.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream responseStream = myHttpWebResponse.GetResponseStream();
StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default);
this.Label1.Text = myStreamReader.ReadToEnd();
myStreamReader.Close();
responseStream.Close();
myHttpWebResponse.Close();
//End Karim
我已经配置了 Office 365 开发人员工具,NuGet,我正在使用 Visual Studio 2015。
请求必须经过身份验证和授权才能请求这些 API。事实上,如果您不提供您代表谁提出此类请求的任何信息,谁会是“/我”?
为此,您应该设置一个所谓的身份验证承载,在您的 C# .NET 调用中,它看起来像这样
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "<your access token as string here>");
要了解如何检索此类访问令牌,请从 this documentation 开始。