typescript - Creating All Day Event failing
问题描述
I'm trying to create an All Day event:
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);
});
});
Log:
When I include the `isAllDay" property, it fails with a 400 (Bad Request).
I exclude the property, and it's creating the event w/out issue.
Any suggestions?
EDIT: forgot to mention, if I pass isAllDay
as false
, the event is created.
EDIT2: This is connecting through the MSGraphClient from an SPFx project.
解决方案
创建“全天”事件时,您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);
});
});
推荐阅读
- node.js - 在 react 中从 cloudant 中获取数据
- php - 在集合中使用 groupBy 时 laravel 更改对象
- node.js - npm:启动脚本失败
- python - 要通过 lambda 排序的列表
- angular - 反应形式的对象成员的角度验证器
- xaml - 如何在 Silverlight 中将“ListView”添加到 Visual Studio 工具箱?
- javascript - 处理相同代码必须立即运行或在承诺解决后运行的最佳方法
- json - 使用 JSONDecoder 解码 PascalCase JSON
- jquery - 水平居中背景图像以实现响应式布局
- python - 生成不在数组中的数字