我正在使用谷歌 API,https://developers.google.com/calendar/v3/reference/events/insert在日历中插入事件。单个事件插入成功,但有没有办法在单个标注中插入多个事件?
最佳答案
您需要使用批处理来添加/删除/更新事件。
为什么要使用批处理? 使用批处理 API 的主要原因是减少网络开销,从而提高性能。
这里是一个例子,展示了使用 javascript/typescript 动态添加事件的批处理,
createMultipleEvents() {
const events = [ {
'summary': 'sample test events1',
'location': 'coimbatore',
'start': {
'date': '2018-08-29',
'timeZone': 'America/Los_Angeles'
},
'end': {
'date': '2018-08-29',
'timeZone': 'America/Los_Angeles'
}
},
{
'summary': 'sample test events2',
'location': 'coimbatore',
'start': {
'date': '2018-08-29',
'timeZone': 'America/Los_Angeles'
},
'end': {
'date': '2018-08-29',
'timeZone': 'America/Los_Angeles'
}
},
];
const batch = gapi.client.newBatch();
events.map((r, j) => {
batch.add(gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': events[j]
}))
})
batch.then(function(){
console.log('all jobs now dynamically done!!!')
});
}
关于google-calendar-api - 在谷歌日历(API)中插入多个 calendar.events,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50467303/