Sync / Share Google Calendar & Nextcloud Calendar

Hi,

Just sharing something i found useful.

context : i am using nextcloud calendar, my wife is still using google calendar. i want to see her calendar (read only) in nextcloud and she wants to see mine (read only) in google.

easiest solution : get her to use your nextcloud server’s calendar !!! :slight_smile:

if for some reason, she does not want to, keep reading.

sharing a google calendar in nextcloud :

  • connect to the google calendar to be shared
  • click on the dented wheel on the top right, to open settings
  • on the nav bar on the left, scroll down to “settings for my calendars”, then develope menu for the calendar to be shared
  • scroll down to “integrate calendar”
  • look for "secret address in ical format and click on “copy” icon
  • head back to nextcloud calendar app
  • click on the plus sign next to “new calendar” on the left nav bar
  • then click on "new subscription from lin (read only)
  • copy paste the link from google calendar, then validate
  • after a few seconds, events from the google calendar should show up
  • profit !

sharing a nextcloud calendar in google :
you could use the subscription link from nextcloud and add it to your google calendar
 but as google only refreshes external calendar not so frequently (like every 24 hours), this is not really a satisfying solution.
after a long time googling for a solution i found this : GitHub - derekantrican/GAS-ICS-Sync: A Google Apps Script for syncing ICS/ICAL files faster than the current Google Calendar speed
as explained in the read me :

  • copy paste this script to your own google app script interface
  • edit the script and modify some values :
  • line 21 paste the subscription link from your nextcloud calendar and choose the calendar name that will appear in google calendar
  • lines 24 to 39 review options and modify as needed (especially refresh interval, by default : 15 min)
  • on the top menu select “install” function", then click on “run”
  • on the top menu select “startSync” function, then click on “run”
  • you will need to grant permissions for this script to edit your calendar
  • after a few seconds events form your nextcloud calendar should show up on your google calendar

nb : obvisouly you have to make sure google can access your nextcloud instance. for example, i had set uo cloudflare in front of my instance to block connections from other countries than mine. i had to add a rule allowing google AS before the rule blocking all countries but mine.

15 Likes

Thanks a lot for this helpful thread !

1 Like

Sadly, it doesn’t seem to work for me. After roughly 24 hours, changes I made in gcal are not synced to nextcloud-calendar. This seems to import gcal, but no sync. Any advice?

best regards

1 Like

Default subscription refresh rate is of one week.
https://docs.nextcloud.com/server/latest/admin_manual/groupware/calendar.html#subscriptions

2 Likes

Hi all,

@nicooo @Gorom @muck @tcit
be aware that sharing like this does not include encryption nor authentication.
So you basically share plain text the calendars (nextcloud and google) to everyone who got the link somehow and every knot on the internet can read it too.
It is meant for public calendars (like concert events).

A secure solution is to make a google / apple account and use for example outlook and caldav to sync between the instances. This is not a superb solution but the only I am aware of which offers security and authentication. If anyone is interested in a more detailed description drop a note.

2 Likes

Hi all

On android:
Use DAVx to sync Contacts & Calendars with your android calendar (like google calendar)

OhaĂŻ !

Thank you so much @nicooo !

For your **sharing a google calendar in nextcloud ** method, do you have any way or idea to make this work with private calendar that needs credentials ?

I tried to find documentation on how I could add them credentials in the url (which I guess is a very bad security habit even if https), or if there was any pop-up/window prompt functionnality to ask for credentials within Nextcloud but meeh

╼(─▜─)╭

If anyone have an idea that would save me, thanks again !

Hi, you can suscribe to a private google calendar without credentials with ical the private link


1 Like

I just add this hack to do if you sync a google calendar on your Nextcloud Calendar.

The refresh rate of a calendar subscription in Nextcloud is once every week by default.

https://docs.nextcloud.com/server/19/user_manual/pim/calendar.html

Subscriptions are refreshed every week by default. Your admin may have changed this setting.

Change the refresh rate:

  • Connect with a terminal in ‘root’ to the Nextcloud instance.
  • Position yourself at the root of the Nextcloud site.
    cd /var/www/nextcloud.example.com/www/ # For example
  • Get the owner of the ‘config.php’ file.
ls -l config/config.php
.rw-r----- nextcloud nextcloud 1.5 KB Wed May 25 10:17:35 2022 config/config.php
  • Change the value of the ‘calendarSubscriptionRefreshRate’ option of the Nextcloud calendar app to 5 minutes.
sudo -u nextcloud php8.0 occ config:app:set dav calendarSubscriptionRefreshRate --value "PT5M"
# RĂ©sultat :
# Config value calendarSubscriptionRefreshRate for app dav set to PT5M
  • Use the user who owns the config file.php with the sudo command. Use the php binary corresponding to the Nextcloud version.
  • Check the consideration.
sudo -u nextcloud php8.0 occ config:list | grep -i calendar
# RĂ©sultat :
#        "calendar": {
#            "calendarSubscriptionRefreshRate": "PT5M",

Crontab

  • Edit the crontab of the user who owns the config file.php seen above.
sudo -u nextcloud crontab -e
  • Add a task every 5 minutes running the php script located at the root of the Nextcloud site.
*/5 * * * * php8.0 -f /var/www/nextcloud.example.com/www/cron.php
  • Use the php binary corresponding to the Nextcloud version.
  • Log in as ‘admin’ on the Nextcloud web interface. Then go to Settings.
  • In the Administration section at the bottom left, go to Basic Settings.
  • Ensure that Background Tasks are configured with ‘Cron’.
    469843cdec6eff1063dff5d85c2f4f1be470e429_2_690x173

Sources

https://www.aukfood.fr/nextcloud-ajouter-un-calendrier-google-prive-sans-credentials/
Using the Calendar app — Nextcloud latest User Manual latest documentation
Calendar / CalDAV — Nextcloud latest Administration Manual latest documentation
PHP: DateInterval::__construct - Manual

4 Likes

Hi @rodinux ,

Can you eleborate what makes a private ical link different from an ical link?

I am unsure what the hack is. You change the refresh interval as described in the Admin documentation too.

Thanks works very well

I’m trying to add a friend’s Google Calendar to my Nextcloud (28.0.1), using the “new subscription from link” feature.

We got the link in my friend’s Google Calendar admin interface, where it reads something like private read-only iCal link. Except the link points to an .ics file. In fact, the URL itself ends with .ics. We didn’t find anything closer to “secret address in ical format”.

Nothing happens, even a week later.

I can download the .ics and import it successfully in the Agenda settings. But obviously, this is not what I’m after.

Are we using the wrong link? Did Google change anything?

Is it the correct link and somehow Nextcloud fails at subscribing/refreshing? (This is the new installation and I never subscribed to any other calendar.)


Subsidiary question about refresh rate. The docs read

Calendar subscriptions are cached on server and refreshed periodically. The default refresh rate is one week, unless the subscription itself tells otherwise.

but I don’t see how to change the refresh rate for a given subscription.

The docs and the post above only teach how to change the default as admin.

1 Like

If you have access to your server by ssh, go to the root folder where nextcloud is installed.
Here the user is nextcloud, look first who is the user, it can be www-data for example, depends of how it have been installed

cd /var/www/netcloud 
sudo -u nextcloud php occ config:app:set dav calendarSubscriptionRefreshRate --value "PT15M"

For my case, with another php version and with apc.enable_cli=1 in the conf I have to do this

cd /var/www/netcloud ;\
sudo -u nextcloud php8.2 --define apc.enable_cli=1 occ config:app:set dav calendarSubscriptionRefreshRate --value "PT15M"

But since version 28 (or before ?) it did not works anymore with the private link

I have an error like this in the logs

"line":1199,"function":"createExtendedCollection","class":"OCA\\DAV\\CalDAV\\CalendarHome","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":560,"function":"createCollection","class":"Sabre\\DAV\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpMkcol","class":"Sabre\\DAV\\CorePlugin","type":"->"},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":472,"function":"emit","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":253,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":321,"function":"start","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/nextcloud/apps/dav/lib/Server.php","line":370,"function":"exec","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/nextcloud/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->"},{"file":"/var/www/nextcloud/remote.php","line":172,"args":["/var/www/nextcloud/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/nextcloud/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php","Line":130}}},"message":"An exception occurred while executing a query: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction","exception":{},"CustomMessage":"An exception occurred while executing a query: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction"}}

Thanks a lot for your hint , do you think 5min or 15min is better to setup ?

For me still working fine, using linuxserver.io container