![](/img/trans.png)
[英]Accessing another user calendar using the O365 REST API from a single domain admin account
[英]O365 Create Events using REST API
我正在尝试调用此代码
string accessToken = @".."; //valid token with right scopes
public string EventsUrl = @"https://outlook.office.com/api/v2.0/me/events";
// generate body
var postBody = JsonBody(invite);
using (var client = new HttpClient())
{
using (var request = new HttpRequestMessage(HttpMethod.Post, EventsUrl))
{
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var content = new StringContent(postBody, Encoding.UTF8, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
return (response.IsSuccessStatusCode);
}
}
创建JsonBody的方法是,
public string JsonBody(User user, Session session){
var invite = new EventInvite
{
Attendees = new Attendee[1]
};
invite.Attendees[0] = new Attendee
{
Type = "Required",
EmailAddress = new Emailaddress { Name = user.GetName(), Address = user.GetEmail() }
};
invite.Start = new Start { DateTime = session.DateTime_Start };
invite.End = new End { DateTime = session.DateTime_Start.AddMinutes(15) };
invite.Subject = session.Name;
invite.Body = new Body { ContentType = "HTML", Content = $"Some Content" };
return JsonConvert.SerializeObject(eventInvite);
}
我收到一个错误的请求作为回应。 是否有其他方法可以建立活动? 我希望这段代码很薄,因为可以在非基于UI的应用程序中访问它
创建日历事件的最佳方法是什么?
该修复程序涉及在“开始”和“结束”中设置时区
string timeZone="Singapore Standard Time";
invite.Start = new Start { DateTime = session.DateTime_Start, TimeZone = timeZone };
invite.End = new End { DateTime = session.DateTime_Start.AddMinutes(60), TimeZone = timeZone };
var postBody = JsonConvert.SerializeObject(invite, Formatting.Indented);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.