typescript - 创建全天事件失败

标签 typescript microsoft-graph-api spfx

我正在尝试创建一个全天事件:

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);
        });
    });

日志:

enter image description here

当我包含 `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/

相关文章:

visual-studio - 尝试对 "$(lastknowntypescriptversion) that evaluates to "进行数字比较“而不是数字

c# - 如何使用用户 ID(对象 ID)从 Azure Active Directory 获取用户名

javascript - 类型 'jquery' 的参数不可分配给类型 'element' 的参数

javascript - TypeScript - 迭代枚举时的奇怪行为

azure - 使用图形 API 获取特定应用程序的 Azure 广告用户列表

rest - checkin / checkout 文件时共享点 `Unsupported segment type`

sharepoint - 命令失败 : wmic os get Caption

javascript - 当属性更改时如何重新渲染 react 组件

microsoft-teams - Teams 选项卡中的 SPFX - 移动应用程序中的滚动问题

reactjs - 无法在Formik/Dist中解析React -自定义WebPack配置