Node.js的freebusy查询中缺少timeMin参数。 Google日历API

时间:2018-02-20 16:14:43

标签: javascript google-calendar-api google-api-nodejs-client

我正在尝试在Node.js中使用google-api-nodejs-client。我对res.json()查询中timeMin参数的格式有疑问。根据{{​​3}},值应该是ISO格式的时间。我试过了,但是我收到了一个错误。在freebusy方法中,ISO格式字符串工作正常。

查询event.list代码:

freebusy

代码function freeBusyStatus (auth, calendarId) { const startDate = new Date('20 February 2018 12:00').toISOString() const endDate = new Date('20 February 2018 13:00').toISOString() const check = { auth: auth, // timeMin: '2018-02-20T12:00:00+03:00', //not working with same format too timeMin: new Date('20 February 2018 12:00'), timeMax: endDate, items: [{id: calendarId}] } calendar.freebusy.query (check, function (err, response) { if (err) { console.log ('error: ' + err) } else { ..some code.. } }) } ,日期为ISO格式。此代码有效:

events.list

我认为问题在于日期格式。当我尝试发送日期为function listEvents(auth, calendarId) { const eventList = { auth: auth, calendarId: calendarId, timeMin: new Date('20 February 2018 12:00').toISOString(), maxResults: 10, singleEvents: true, orderBy: 'startTime' } calendar.events.list(eventList, function(err, response) { if(err) { console.log(err) } const events = response.data.items if (events.length != 0) { ..some code.. } }) } (没有时间)的请求时,响应会出现同样的错误2018-02-20

我做错了什么?授权是通过JWT完成的。

1 个答案:

答案 0 :(得分:5)

完成!我的错误在于请求结构

function freeBusyStatus (auth, calendarId) {
    const check = {
        auth: auth,
        resource: {
            timeMin: startDate,
            timeMax: endDate,
            items: [{id: calendarId}]
        }
    }
    const startDate = new Date('20 February 2018 12:00').toISOString()
    const endDate = new Date('20 February 2018 13:00').toISOString()
    calendar.freebusy.query (check, function (err, response) {
        if (err) {
            console.log ('error: ' + err)
        } else {
            ..some code..
        }
    })
}