Hubot谷歌日历免费忙碌说时间没有设置

时间:2014-08-07 17:27:17

标签: coffeescript google-api google-calendar-api

我正在尝试编写一个hubot脚本来轮询Google日历,以获取每个日历的忙碌信息。问题是请求返回错误消息:Missing timeMin parameter,即使在正文中设置了timeMin。

module.exports = (robot) ->
robot.respond /ar|what (room|rooms) (is|are) available\?|available (rooms|room)\?/i, (msg) ->
apiKey = 'MyAPIkey'
url = "https://www.googleapis.com/calendar/v3/freeBusy?key=#{ apiKey }"
d = new Date()
now = d.toISOString()
endOfDay = "#{ now.substr(0, 11) }23:59:59#{ now.substr(19) }"

roomCalendars = []

for alias, room of rooms
  roomCalendars.push room.id

post_data = JSON.stringify({
  'timeMin': now
  'timeMax': endOfDay
  items: roomCalendars
})

robot.http(url)
  .post(post_data) (err, res, body) ->
      if err or res.statusCode isnt 200
          msg.send 'I\'ve encountered an error trying to get an available room. Sorry!'
          return
        msg.send 'Here'

返回:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Missing timeMin parameter."
   }
  ],
  "code": 400,
  "message": "Missing timeMin parameter."
 }
}

post_data是:

{"timeMin":"2014-08-07T18:11:27.761Z","timeMax":"2014-08-07T23:59:59.761Z","items":[{"id":"id1"},{"id":"id2"},{"id":"id3"},{"id":"id4"},{"id":"id5"}]}

0 个答案:

没有答案