我正在尝试创建一个全天事件:
let foobar: any = {
"subject": calendarEvent.Title+"v5",
"body": {
"contentType": "HTML",
"content": calendarEvent! || !calendarEvent.Description ? "No Description": calendarEvent.Description,
},
"start": {
"dateTime": calendarEvent.EventDate,
"timeZone": moment.tz.guess(),
},
"end": {
"dateTime": calendarEvent.EndDate,
"timeZone": moment.tz.guess(),
},
"location": {
"displayName": !calendarEvent || !calendarEvent.Location ? "No Location": calendarEvent.Location,
},
"isAllDay": !calendarEvent || !calendarEvent.fAllDayEvent ? false : true,
};
context.msGraphClientFactory.getClient()
.then((client: MSGraphClient) => {
client.api("/me/calendar/events").post(foobar)
.then((content: any) => {
console.log("CalendarService | createCalendarEvent | content: ", content);
});
});
日志:
当我包含 `isAllDay"属性时,它失败并显示 400(错误请求)。
我排除了该属性,它正在创建没有问题的事件。
有什么建议吗?
编辑:忘了说,如果我将 isAllDay
传递为 false
,则会创建事件。
EDIT2:这是通过来自 SPFx 项目的 MSGraphClient 进行连接。
最佳答案
创建“全天”事件时,开始
和结束
时间应仅指定日期,而不是日期和时间 (或者更准确地说,时间应该是 00:00:00):
let foobar: any = {
"subject": calendarEvent.Title+"v5",
"body": {
"contentType": "HTML",
"content": calendarEvent! || !calendarEvent.Description ? "No Description": calendarEvent.Description,
},
"start": {
"dateTime": !calendarEvent.fAllDayEvent ? calendarEvent.EventDate : calendarEvent.EventDate.setTime(0),
"timeZone": moment.tz.guess(),
},
"end": {
"dateTime": !calendarEvent.fAllDayEvent ? calendarEvent.EventDate : calendarEvent.EventDate.setTime(0),
"timeZone": moment.tz.guess(),
},
"location": {
"displayName": !calendarEvent || !calendarEvent.Location ? "No Location": calendarEvent.Location,
},
"isAllDay": !calendarEvent || !calendarEvent.fAllDayEvent ? false : true,
};
context.msGraphClientFactory.getClient()
.then((client: MSGraphClient) => {
client.api("/me/calendar/events").post(foobar)
.then((content: any) => {
console.log("CalendarService | createCalendarEvent | content: ", content);
});
});
关于typescript - 创建全天事件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53122667/