Search code examples
javascriptcalendargoogle-calendar-apigoogle-api-js-client

Google API (Javascript) - Add calendar to calendarList manually


So I'm currently using the Google API Javascript and have run into a bit of a problem. I am manually building a calendar by first calling gapi.client.calendar.calendarList.list which gives me a list of accessible calendars to pull information from (ie. event data). However, for whatever reason this requires the user to have first added the calendar to the "Other Calendars" section of the Calendar. (See attached photo).

Since this requires too much grief on the end-user, I was wondering if I could add in the calendar to calendarList manually using the calendar's resource id / email address.

I was looking at gapi.client.calendar.calendarList.update, but it doesn't seem to work as advertisted. Does anyone have any experience with manually loading a calendar into calendarList so that it can be called by calendarList.list and ultimately deliver event information?


Solution

  • Yes this is possible. The Calendars.insert allows one to manually create a secondary calendar and be added to their "My calendars" account or any specified calendar. Here are all the properties.

    • id: Identifier of the calendar.
    • summary: Title of the calendar.
    • timeZone: The time zone of the calendar. Optional.
    • description: Description of the calendar. Optional.
    • location: Geographic location of the calendar as free-form text. Optional.
    • kind: Type of the resource ("calendar#calendar").
    • etag: ETag of the resource.

    You can Try-it to make sure it is working as you expected. Hope this helps and Good luck!