谷歌日历API - 插入事件时出现“缺少结束时间”错误

4

我正在尝试使用Google Calendar API在Google日历中插入一个事件。

我要插入的事件资源如下:

{
  "summary": "test",
  "location": "test",
  "description": "test",
  "start": {
    "dateTime": "2015-11-02T10:00:00-05:00",
    "timeZone": "America/Toronto"
  },
  "end": {
    "dateTime": "2015-11-02T11:00:00-05:00",
    "timeZone": "America/Toronto"
  },
  "attachments": [
    {
      "fileUrl": ""
    }
  ],
  "attendees": [
    {
      "email": "...@gmail.com"
    },
    {
      "email": "...@gmail.com"
    }
  ],
  "reminders": {
    "useDefault": false,
    "overrides": [
      {
        "method": "email",
        "minutes": 1440
      },
      {
        "method": "popup",
        "minutes": 10
      }
    ]
  }
}

这个事件作为一个POST请求的主体被发送到https://www.googleapis.com/calendar/v3/calendars/calendarId/events。我没有使用任何库。
我始终得到一个“缺少结束时间”的错误。我发现了一些类似的问题,比如这个,(s)he正在使用Javascript库,并建议将以下内容作为主体发送:
{
    resource:<event above>,
    calendarId:<calendarId>
}

但是在我的情况下,这并没有起作用,也许是因为我没有使用库。我不认为这很重要,但我是在Meteor应用程序内部执行此操作。有什么想法吗?

编辑 事实证明这确实是Meteor相关的问题。我在使用他们的HTTP库时犯了一个错误。

1个回答

1

此事件作为POST请求的主体发送到https://www.googleapis.com/calendar/v3/calendars/calendarId/events。

不确定这是否是一个错字,但我使用“尝试”并使用您的日期发送了请求,它可以工作,我发布到了我的主要日历中。

POST https://www.googleapis.com/calendar/v3/calendars/primary/events?key={YOUR_API_KEY}

它不是一个字符串的calendarId,而是你想要插入的日历的id。你还需要在末尾添加访问令牌。

POST https://www.googleapis.com/calendar/v3/calendars/primary/events?key={YOUR_API_KEY}
{
 "end": {
  "dateTime": "2015-11-02T11:00:00-05:00",
  "timeZone": "America/Toronto"
 },
 "start": {
  "dateTime": "2015-11-02T10:00:00-05:00",
  "timeZone": "America/Toronto"
 },
 "description": "test",
 "summary": "test"
}

结果证明这是一个与Meteor相关的问题。我在使用他们的http库时犯了一个错误。对此我感到抱歉,谢谢。 - znat
我试过这个,因为我曾经遇到过日期的问题。它可能有些棘手。 - Linda Lawton - DaImTo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接