使用nodejs Google日历API插入事件返回400:“缺少结束时间” [英] Inserting an event with the nodejs google calendar API returns 400: "Missing end time"
问题描述
我试图通过Google Calendar API和服务帐户插入活动。目标是让所有用户查看一个日历:服务器到服务器的设置。
截至目前,我可以正确调用日历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,
字段:{
items:[ (err){
console.log(err);} $ {
$ b},function(err,CL)
} else {
console.log(CL);
}
});
}
})
这会正确返回一个JSON对象,该对象列出日历上的所有不同对象。但是,当我尝试在 googleCal.events.list
调用的正下方插入事件时:
googleCal.events.insert({
auth:authClient,
calendarId:primary,
资源:{
start:{
dateTime :2014-07-23T18:25:00.000-07:00,
timeZone:America / New_York
},
结束:{
dateTime:2014- 07-23T19:25:00.000-07:00,
timeZone:America / New_York
},
总结:赢得@生命,
描述:获胜@ life description
}
},function(err,something){
if(err){
console.log(err);
} else {
console.log(something);
//做别的事情
}
})
返回以下 400
:
{errors:
[{domain:'global',
reason:'required' ,
message:'Missing end time。'}],
code:400,
message:'Missing end time。'}
我该如何解决这个问题?授权显然是有效的 - 我知道,因为我已经用完了当天的未授权请求,因为我可以列出所有事件。我还指定了一个 endTime
。为什么google calendar API告诉我我没有?解决方案
我认为问题出在关键字resources在你的第二个片段的第4行。基于文档,它应该是一个资源:
* @param {object} params.resource - 请求正文数据
I am trying to insert events via the Google Calendar API with a service account. 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:
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. However, when I try to insert an event directly below the googleCal.events.list
call:
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:
{ 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
. Why is the google calendar API telling me that I haven't?
I think the problem is in the keyword "resources" on line 4 of your second snippet. Based on the documentation, it should be a "resource":
* @param {object} params.resource - Request body data
这篇关于使用nodejs Google日历API插入事件返回400:“缺少结束时间”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!