创建一个 ID 为 Google 日历的事件:Google 脚本
Create an Event with an ID to Google Calendar: Google Script
我正在尝试将活动添加到 Google 日历,但在这样做时没有添加活动。我确信代码正在解决它。有谁知道为什么没有将活动添加到日历中?
我会添加整个代码,但我觉得它没有抓住重点。
var calendarId = "Typed Out ID of Calendar";
var calendar = CalendarApp.getCalendarById(calendarId);
calendar.createEvent('Breakfast',
new Date("April 19, 2021"));
您可以使用它来显示您的日历 ID:
function displayCalendarInfo() {
var cals=CalendarApp.getAllCalendars();
var s='Calendar Information';
for(var i=0;i<cals.length;i++)
{
s+=Utilities.formatString('<br />Name: %s Id: %s', cals[i].getName(),cals[i].getId());
}
s+='<br /><input type="button" value="Close" onClick="google.script.host.close();" />';
var ui=HtmlService.createHtmlOutput(s).setWidth(1200).setHeight(450);
SpreadsheetApp.getUi().showModelessDialog(ui, 'Calendar Data');
}
只是为了确保您使用了正确的 ID。
创建事件:(有效)
function createEvent() {
const cal = CalendarApp.getCalendarById('id');
const start = new Date(2021,3,20,10,30,0,0);//4/20/2021 10:30:00
const end = new Date(2021,3,20,11,30,0,0);//4/20/2021 11:30:00
cal.createEvent('new event',start,end);
}
月份范围从 1 月到 12 月,即 0 到 11,比您预期的少一个
我正在尝试将活动添加到 Google 日历,但在这样做时没有添加活动。我确信代码正在解决它。有谁知道为什么没有将活动添加到日历中?
我会添加整个代码,但我觉得它没有抓住重点。
var calendarId = "Typed Out ID of Calendar";
var calendar = CalendarApp.getCalendarById(calendarId);
calendar.createEvent('Breakfast',
new Date("April 19, 2021"));
您可以使用它来显示您的日历 ID:
function displayCalendarInfo() {
var cals=CalendarApp.getAllCalendars();
var s='Calendar Information';
for(var i=0;i<cals.length;i++)
{
s+=Utilities.formatString('<br />Name: %s Id: %s', cals[i].getName(),cals[i].getId());
}
s+='<br /><input type="button" value="Close" onClick="google.script.host.close();" />';
var ui=HtmlService.createHtmlOutput(s).setWidth(1200).setHeight(450);
SpreadsheetApp.getUi().showModelessDialog(ui, 'Calendar Data');
}
只是为了确保您使用了正确的 ID。
创建事件:(有效)
function createEvent() {
const cal = CalendarApp.getCalendarById('id');
const start = new Date(2021,3,20,10,30,0,0);//4/20/2021 10:30:00
const end = new Date(2021,3,20,11,30,0,0);//4/20/2021 11:30:00
cal.createEvent('new event',start,end);
}
月份范围从 1 月到 12 月,即 0 到 11,比您预期的少一个