Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 93 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save gene1wood/02ed0d36f62d791518e452f55344240d to your computer and use it in GitHub Desktop.
Save gene1wood/02ed0d36f62d791518e452f55344240d to your computer and use it in GitHub Desktop.

Given a subscribed calendar with a url like

https://example.com/example.ics

To force Google Calendar to refresh and reload the contents right now, unsubscribe from the calendar and subscribe to a new calendar with a URL like

https://example.com/example.ics#1

Adding the anchor tag will force Google Calendar to think of it as a new calendar

Many people who come to this gist are not looking for a one time forced refresh but instead to refresh recurringly. If that's you, you should check out @derekantrican 's Google App Script

https://github.com/derekantrican/GAS-ICS-Sync

Which can refresh a calendar automatically every N minutes

https://script.google.com/home/projects/1BOk8MDLbLaHh6SwG1M1tsgNXjkcC-79LE0QoipRuTDxbO3fMVvqoROQD/edit

Thanks to @rattrayalex for pointing people to this script

@Kavadera
Copy link

Kavadera commented Aug 4, 2023

Turned out, if you run the script without editing the ICS link, the script crashes and self-destroys itself. After I recreated another copy and added the URL to calendar ICS , the error didn't appear again. Not very user-friendly, but it finally works. Thanks to the author!

@AdvancedDataIT
Copy link

The Google script worked for me!

Now my outlook 365 calendar via .ics refreshes every minute on gmail :). Thank you for the help.

@MrRendroc
Copy link

Any recommendations for the interval for refreshing? Are there any problems with a short interval that refreshes the calendar too frequently?

@Brinkmann
Copy link

I have set mine to every 15 minutes and have had no issues.

@rob-prime
Copy link

Just to help people out if they need it:

  • On the "Code.gs" page, when you follow step 1 and click on the ⓘ, then click the "copy" icon on the top right (looks like two files on top of each other), a new window/tab will open with a Google Apps Scripts project called Copy of GAS-ICS-Sync that you will then customize

  • On the "Code.gs" page, when you follow step 2, you want to go down to Line 28 of the script code and replace:
    icsUrl1
    ...with the URL of the subscribed calendar that you want Google-Calendar to re-fresh or re-sync with

and also replace:
targetCalendar1
...with the Name of the calendar in Google-Calendar that corresponds to the subscribed calendar
NOTE - I did not type the name of the subscribed calendar exactly the same by mistake, and a new subscribed calendar was created under "My Calendars" that was a duplicate of the previously subscribed calendar under "Other Calendars" - this was no big deal, I just un-ticked the subscribed calendar under "Other calendars" for now (I could remove it completely if I want)

  • Repeat the above 2 steps if you have additional calendars

  • Otherwise, you can delete the lines of code that have example text for other calendars

  • Then follow the rest of the instructions (I left the other lines of code as-is; the info on the "Code.gs" pages explains what all the settings are and you can decide how to set them)

It works for me, and I had never done anything like this before!

@dracunciliasis
Copy link

dracunciliasis commented Sep 18, 2023

Is there a way to re-share the resulting google calendar.
I want to share with my family (wife and kids) the google calendar created by this script, If I can re-share, I do not have to install the scripts in all family accounts. Currently it is not possible to re-share in google calendar user interface.

@mmozzano
Copy link

Just one quick note. I dont use Chrome. I notice when I tried to install this script using Firefox, when it asks to approve the permissions I was getting 'Something went wrong. Please try again later'.

Had to use Edge for it to install successfully and grant the relevant permissions.

@mhardy
Copy link

mhardy commented Oct 20, 2023

https://script.google.com/home/projects/1BOk8MDLbLaHh6SwG1M1tsgNXjkcC-79LE0QoipRuTDxbO3fMVvqoROQD/edit

This is fantastic, thanks! One change to Settings would be nice:

var onlyFutureEvents = true;
// If you turn this to "true", past events will not be synced (this will also removed past events from the target calendar if removeEventsFromCalendar is true)

It would be nice to have onlyFutreEvents true to make the sync faster, but also leave removeEventFromCalendar also true so any future events that are deleted get removed, but past events aren't touched.

@Omi0
Copy link

Omi0 commented Oct 26, 2023

This is absolutely fabulous! Million thanks to @derekantrican for making it!

@SysC0mp
Copy link

SysC0mp commented Nov 13, 2023

Thank you very much for that. Awesome!

@kennysarmy1
Copy link

I am trying to use this great tool, but after a few entries are added to my calendar the output log shows:

Dec 1, 2023, 10:45:39 AM Error API call to calendar.events.insert failed with error: Bad Request
at callWithBackoff(Helpers:939:9)
at processEvent(Helpers:241:20)
at unknown function
at startSync(Code:202:15)

and then no further entries are added.

Any ideas?

This is the ICS file:
webcal://clubv1.blob.core.windows.net:443/diary-events/127/5bff3598-4200-4f24-ac99-d4c38f3ca6b2.ics

@jonas0b1011001
Copy link

I am trying to use this great tool, but after a few entries are added to my calendar the output log shows:

Dec 1, 2023, 10:45:39 AM Error API call to calendar.events.insert failed with error: Bad Request at callWithBackoff(Helpers:939:9) at processEvent(Helpers:241:20) at unknown function at startSync(Code:202:15)

and then no further entries are added.

Any ideas?

This is the ICS file: webcal://clubv1.blob.core.windows.net:443/diary-events/127/5bff3598-4200-4f24-ac99-d4c38f3ca6b2.ics

@kennysarmy1 The file you are trying to sync does not comply to the ical standard. Have a look at derekantrican/GAS-ICS-Sync#289 derekantrican/GAS-ICS-Sync#237 for similar reports.

@orvilleboggs
Copy link

When I use the anchor tag (#1) to update my calendar, it works perfectly. I added the anchor tag to the webcal url in Google Calendar. I don’t want to go in manually and change the calendar all the time, so I installed the script and I run it without errors but my calendar is not updating.

On line 28 ["icsUrl1", "targetCalendar1"], I added in my target url and calendar name.

This is the webcal url for the calendar: webcal://p114-caldav.icloud.com/published/2/OTU0NTQwNzk1NDU0MDc5NY0GfaMdNrmofxaskYFk8I9ZnMV1JBhhZIkTGL90GL00#1

This is the public url to this calendar from Google: https://calendar.google.com/calendar/embed?src=udru2fk5hldka3rbj4u9cm5frb63b6f0%40import.calendar.google.com&ctz=America%2FNew_York

I’m pretty sure that I am making a mistake with the url. I tried many different combinations from above but no luck. I was hoping that someone could point me in the right direction? Thank you!!

@jonas0b1011001
Copy link

On line 28 ["icsUrl1", "targetCalendar1"], I added in my target url and calendar name.

You have to add the source url not the target url. The second item is the name of the google calendar you want to sync to (in case you want to sync to your main calendar you have to use the account gmail address)

@orvilleboggs
Copy link

On line 28 ["icsUrl1", "targetCalendar1"], I added in my target url and calendar name.

You have to add the source url not the target url. The second item is the name of the google calendar you want to sync to (in case you want to sync to your main calendar you have to use the account gmail address)

@jonas0b1011001 Thank you so much for the quick response! I really appreciate it! I will add the source file in a bit. Thanks!

@orvilleboggs
Copy link

I finally got this working and it’s great! I wanted to post a mistake I was making in case it helps anyone out in the future. It seems like a simple mistake but took me a few days to figure out.

I created a calendar in Google from an iCloud url called “Appointments.” It was a read-only calendar. When I added in my source url and target calendar on code.gs line 28, nothing worked. I thought I was inputting the wrong url.

After searching the boards, I realized I needed to create a new calendar in Google and delete the read-only calendar. I called the new calendar “Appointments” as well. I put in my source url and the target calendar (Appointments) and everything worked. Hope this makes sense and I hope it helps.

@andreamoro-git
Copy link

Is the issue arising only because google calendar refreshes infrequently, or is it because they NEVER refresh? I am almost certain that some of the calendars I subscribe to are updated from time to time but I never checked how promptly

@orvilleboggs
Copy link

It's because google calendar refreshes infrequently. I'm not sure how long it takes to refresh but it is a considerable amount of time. It will update eventually but I wanted it to refresh much more quickly. This solved the problem for me.

@andreamoro-git
Copy link

andreamoro-git commented Jan 30, 2024

ok thanks but does infrequently mean hours or days/weeks?

@orvilleboggs
Copy link

It usually takes some where between 12 and 24 hours to refresh.

@malazarocom
Copy link

Great!

@olgabot
Copy link

olgabot commented Mar 15, 2024

Thank you so much! @derekantrican, you are a lifesaver!

@TDReservas
Copy link

Hi all, This is fantastic really saved me a headache and works great. I have 50 Air Bnb properties that I manage and need all there calenders in one place.

Because of this, is it possible to add unlimited calenders to this script? and if so how do i do this? do I just copy and paste into new inserted lines?

First time using scripts etc

TIA

@jonas0b1011001
Copy link

is it possible to add unlimited calenders to this script?

Of course, you can either combine x calendars into one google calendar or sync them all to a different google calendar.

Just edit/add additional calendars to:

var sourceCalendars = [                
  ["icsUrl1", "targetCalendar1"],
  ["icsUrl2", "targetCalendar2"],
  ["icsUrl3", "targetCalendar1"]
];

Make sure to get the commas at the line ends correct ;)

@TDReservas
Copy link

is it possible to add unlimited calenders to this script?

Of course, you can either combine x calendars into one google calendar or sync them all to a different google calendar.

Just edit/add additional calendars to:

var sourceCalendars = [                
  ["icsUrl1", "targetCalendar1"],
  ["icsUrl2", "targetCalendar2"],
  ["icsUrl3", "targetCalendar1"]
];

Make sure to get the commas at the line ends correct ;)

Thankyou thats fantastic, So how do Iput them all into 1 calender? I just put the same name for target calendar?

@jonas0b1011001
Copy link

I just put the same name for target calendar?

Yes

@Johnyryal
Copy link

Johnyryal commented Apr 3, 2024

Hi, this is just what I was looking for and have it setup and running. It has created and populated a new calendar in my google calendar with the ics data. I have added a new entry in the iCal source to see that it is working. When it runs I don't ever see the new entry populate in the google calendar and under executions I get one of these two entries. Timing is set to every 15 minutes. Any thoughts or guidance would be helpful. Thanks.

Info - Completed:
Another iteration is currently running! Exiting...

Error - Failed:
DNS error: http://h
at callWithBackoff(Helpers:1078:9)
at fetchSourceCalendars(Helpers:136:5)
at startSync(Code:168:21)

@jonas0b1011001
Copy link

Hi, this is just what I was looking for and have it setup and running. It has created and populated a new calendar in my google calendar with the ics data. I have added a new entry in the iCal source to see that it is working. When it runs I don't ever see the new entry populate in the google calendar and under executions I get one of these two entries. Timing is set to every 15 minutes. Any thoughts or guidance would be helpful. Thanks.

Info - Completed: Another iteration is currently running! Exiting...

Error - Failed: DNS error: http://h at callWithBackoff(Helpers:1078:9) at fetchSourceCalendars(Helpers:136:5) at startSync(Code:168:21)

Your var sourceCalendars is missing a set of [], recheck with the given example.


Many of the questions asked here are already answered in the official repo of the script. As one of the maintainers, I can only encourage anyone to head over there if they are facing problems with the script!

@Johnyryal
Copy link

Hi, this is just what I was looking for and have it setup and running. It has created and populated a new calendar in my google calendar with the ics data. I have added a new entry in the iCal source to see that it is working. When it runs I don't ever see the new entry populate in the google calendar and under executions I get one of these two entries. Timing is set to every 15 minutes. Any thoughts or guidance would be helpful. Thanks.
Info - Completed: Another iteration is currently running! Exiting...
Error - Failed: DNS error: http://h at callWithBackoff(Helpers:1078:9) at fetchSourceCalendars(Helpers:136:5) at startSync(Code:168:21)

Your var sourceCalendars is missing a set of [], recheck with the given example.

Many of the questions asked here are already answered in the official repo of the script. As one of the maintainers, I can only encourage anyone to head over there if they are facing problems with the script!

Thank you @jonas0b1011001 for helping me correct my error. Sorry I couldn't find my answer in the repo. My error for "cleaning up" to much of the comments in that line. Many thanks!

@gene1wood
Copy link
Author

@jonas0b1011001 Given that most people who come to this gist are looking for functionality provided by your project ( https://github.com/derekantrican/GAS-ICS-Sync ), not for the trick outlined above about adding an anchor tag to a URL, is there anything you'd like to see me change/update about this gist to try to get those users away from this gist and over to your repo? Maybe I go through and try to delete some old comments in order to simplify this landing page so it's easier for people to find their way to your repo? Any ideas are welcome. I have a contact form linked on my GitHub profile, feel free to use it to email me with any ideas for how to improve this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment