【问题标题】:Google Calendar API NodeJS - specify fieldsGoogle Calendar API NodeJS - 指定字段
【发布时间】:2013-10-26 18:07:41
【问题描述】:

嘿嘿,我在我的 NodeJS 项目中使用 google-api-nodejs-client 包,我正在尝试构建我的日历事件查询。它工作正常,但我无法指定“字段”字段。

这会返回五个完整的日历事件:

client.calendar.events.list({
    calendarId: gcal_id,
    maxResults: 5
})
.withAuthClient(authClient)
.execute(function(err, calendar) {
    if (err)
        console.log(err);
    else
        console.log(calendar);
});

但这什么也没返回:

client.calendar.events.list({
    calendarId: gcal_id,
    maxResults: 5,
    fields: {
        items: ["end","start","status","summary"]
    }
})
.withAuthClient(authClient)
.execute(function(err, calendar) {
    if (err)
        console.log(err);
    else
        console.log(calendar);
});

我也试过了:

fields: {
    items: "end,start,status,summary"
}

基于 Google Calendar V3 API,我应该能够进行如下查询: https://www.googleapis.com/calendar/v3/calendars/gcal_id.google.com/events?maxResults=5&fields=items(end%2Cstart%2Cstatus%2Csummary)&key={YOUR_API_KEY}

我不确定如何指定 URL 的“fields=items(end%2Cstart%2Cstatus%2Csummary)”部分,但我已经在 Google 的 API Explorer 中对其进行了测试,并且它有效,所以我知道我'我在 JavaScript 中做错了什么。

任何帮助将不胜感激。现在我想我会清理从第一个代码 sn-p 得到的响应。

【问题讨论】:

    标签: google-api-nodejs-client


    【解决方案1】:

    好吧,我想通了。它应该是一个字符串。

    fields: "items(end,start,status,summary)"
    

    【讨论】:

    • 只是想补充一点,截至 2017 年 3 月 6 日,如果您指定 fields,它只会返回指定的字段。例如,如果您传递"items(summary)",则只会返回每个项目的摘要。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 2013-01-02
    • 2018-03-23
    相关资源
    最近更新 更多