简体   繁体   English

使用nodejs谷歌日历API插入事件会返回400:“缺少结束时间”

[英]Inserting an event with the nodejs google calendar API returns 400: “Missing end time”

I am trying to insert events via the Google Calendar API with a service account. 我正在尝试通过带有服务帐户的Google Calendar API插入事件。 The goal is to have one calendar that all users view: a server-to-server setup. 目标是拥有一个可供所有用户查看的日历:服务器到服务器的设置。

As of now, I can properly call the calendar API and list the events on said calendar: 到目前为止,我可以正确调用日历API并在所述日历上列出事件:

var moment = require("moment"),
    googleapis = require("googleapis"),
    googleCal = googleapis.calendar("v3");
    serviceEmail = "********@developer.gserviceaccount.com",
    serviceKeyFile = "./key.pem";

var authClient = new googleapis.auth.JWT(
        serviceEmail,
        serviceKeyFile,
        null,
        ["https://www.googleapis.com/auth/calendar"]
    );

authClient.authorize(function (err, tokens) {
    if (err) {
        console.log(err);
    } else {
        googleCal.events.list({
            auth: authClient,
            calendarId: "********@gmail.com",
            fields: {
                items: ["end","start","summary"]
            }
        }, function (err, CL) {
            if (err) {
                console.log(err);
            } else {
                console.log(CL);
            }
        });
    }
})

This properly returns a JSON object that lists all the different objects on the calendar. 这将正确返回一个JSON对象,该对象列出了日历上的所有不同对象。 However, when I try to insert an event directly below the googleCal.events.list call: 但是,当我尝试在googleCal.events.list调用下方直接插入事件时:

googleCal.events.insert({
    auth: authClient,
    calendarId: "primary",
    resources: {
        start: {
          dateTime: "2014-07-23T18:25:00.000-07:00",
          timeZone: "America/New_York"
        }, 
        end: {
          dateTime: "2014-07-23T19:25:00.000-07:00",
          timeZone: "America/New_York"
        }, 
        summary: "winning @ life",
        description: "winning @ life description"
    }
}, function (err, something) {
    if (err) {
        console.log(err);
    } else {
        console.log(something);
        // do something else
    }
})

The following 400 is returned: 返回以下400

{ errors: 
    [ { domain: 'global',
        reason: 'required',
        message: 'Missing end time.' } ],
  code: 400,
  message: 'Missing end time.'}

How do I go about fixing this? 我该如何解决这个问题? The authorization is clearly working—I know because I've used up my unauthorized requests for the day and because I can list all the events. 授权显然很有效-我知道这是因为当天我已经用完了所有未经授权的请求,并且可以列出所有事件。 I have also specified an endTime . 我还指定了一个endTime Why is the google calendar API telling me that I haven't? 为什么Google Calendar API告诉我还没有?

I think the problem is in the keyword "resources" on line 4 of your second snippet. 我认为问题出在第二个片段的第4行的关键字“ resources”中。 Based on the documentation, it should be a "resource": 根据文档,它应该是“资源”:

 * @param  {object} params.resource - Request body data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM