【问题标题】:Creating All Day Event failing创建全天事件失败
【发布时间】:2019-04-06 22:33:30
【问题描述】:

我正在尝试创建全天活动:

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 进行连接。

【问题讨论】:

  • 您访问的是什么 API?
  • @cmaynard MSGraph
  • 会不会是你的开始和结束时间不是午夜:eliostruyf.com/…
  • @cmaynard,谢谢。

标签: typescript microsoft-graph-api spfx


【解决方案1】:

创建“全天”事件时,startend 时间应该只指定日期,而不是日期和时间(或更准确地说,时间应该是 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);
        });
    });

【讨论】:

  • 这实际上是问题所在,正如我在 cmets 中指出的那样,感谢您提供代码示例。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-18
  • 2014-04-22
相关资源
最近更新 更多