admin管理员组文章数量:1434949
I'm trying to mass create events into a Google Calendar using the Google Calendar API. I've been able to have to events appear from my google sheet into my main personal calendar, but not in the specified calendar. I want to be able to share just these events instead of sharing my entire personal calendar later . Here's my code from google apps script.
function create_Events(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var last_row = sheet.getLastRow();
var data = sheet.getRange("B1:D" + last_row).getValues();
var cal = CalendarApp.getCalendarById("[email protected]");
//Logger.log(data);
for(var i = 0;i< data.length;i++){
//index 0 =
var event = CalendarApp.getDefaultCalendar().createEvent(data[i][0],
new Date(data[i][1]),
new Date(data[i][2]),
{location: data[i][3]});
Logger.log('Event ID: ' + event.getId());
}
}
I copied the Calendar ID from the calendar settings, expecting the events to populate in that calendar. Instead they populated into the calendar tied to my gmail account
I'm trying to mass create events into a Google Calendar using the Google Calendar API. I've been able to have to events appear from my google sheet into my main personal calendar, but not in the specified calendar. I want to be able to share just these events instead of sharing my entire personal calendar later . Here's my code from google apps script.
function create_Events(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var last_row = sheet.getLastRow();
var data = sheet.getRange("B1:D" + last_row).getValues();
var cal = CalendarApp.getCalendarById("[email protected]");
//Logger.log(data);
for(var i = 0;i< data.length;i++){
//index 0 =
var event = CalendarApp.getDefaultCalendar().createEvent(data[i][0],
new Date(data[i][1]),
new Date(data[i][2]),
{location: data[i][3]});
Logger.log('Event ID: ' + event.getId());
}
}
I copied the Calendar ID from the calendar settings, expecting the events to populate in that calendar. Instead they populated into the calendar tied to my gmail account
Share Improve this question asked Nov 17, 2024 at 12:08 user28338128user28338128 11 silver badge1 bronze badge1 Answer
Reset to default 1Create Google event in Calendar
You can try this Code:
function create_Events() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var last_row = sheet.getLastRow();
var data = sheet.getRange("B1:D" + last_row).getValues();
var cal = CalendarApp.getCalendarById("Your calendar ID");
for (var i = 0; i < data.length; i++) {
var event = CalendarApp.getCalendarById(cal).createEvent(data[i][0],
new Date(data[i][1]),
new Date(data[i][2]),
{ location: data[i][3] });
Logger.log('Event ID: ' + event.getId());
}
}
I modified this section of your code:
var event = CalendarApp.getDefaultCalendar().createEvent(data[i][0],
new Date(data[i][1]),
new Date(data[i][2]),
{ location: data[i][3] });
When running the code, the default calendar is accessed
. You need to open the calendar by its ID
where you plan to work.
Reference:
Calendar - GetCalendarbyID
本文标签: Events appearing in wrong Google CalendarStack Overflow
版权声明:本文标题:Events appearing in wrong Google Calendar - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745636222a2667572.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论