简体   繁体   中英

Add Google Calendar Event to non Primary calendar

I am trying to add an event to a newly created calendar. The calendar can be created like so:

gapi.client.calendar.calendars.insert(
 {
     "resource" :
     {"summary": "Test Cal",
     "description": "test",
     "timezone" : "xxxx"}
 });

Is there anyway to now determine the calendarId? Right now an event is added to the "primary" calendar.

var request=gapi.client.calendar.events.insert({
             "calendarId": "primary",
             resource:{
                 "summary":.....

How can I add the event to the newly created calendar?

I literally just had to solve the same problem:

var calendarID;
var req = gapi.client.calendar.calendarList.list({});
    req.execute(function(resp) {
        for (var i = 0; i < resp.items.length; i++) {
            if (resp.items[i].summary === "Newly Created Schedule") {
                console.log("Newly Created Schedule ID: " + resp.items[i].id);
                calendarID = resp.items[i].id;
                break;
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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