创建全天事件失败
Creating All Day Event failing
我正在尝试创建全天活动:
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(错误请求)。
我排除了 属性,它正在创建事件 w/out 问题。
有什么建议吗?
编辑: 忘记提及,如果我将 isAllDay
作为 false
传递,则创建事件。
EDIT2:这是通过来自 SPFx 项目的 MSGraphClient 连接。
创建 "All Day" 事件时,您 start
和 end
时间应该只指定 日期 ,而不是日期和时间 (或者更准确地说,时间应该是 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);
});
});
我正在尝试创建全天活动:
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(错误请求)。
我排除了 属性,它正在创建事件 w/out 问题。
有什么建议吗?
编辑: 忘记提及,如果我将 isAllDay
作为 false
传递,则创建事件。
EDIT2:这是通过来自 SPFx 项目的 MSGraphClient 连接。
创建 "All Day" 事件时,您 start
和 end
时间应该只指定 日期 ,而不是日期和时间 (或者更准确地说,时间应该是 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);
});
});