Caldav google calendar problem

Hello, I’ve configered calDAV as described up there. I Still have an error:

2018-02-11 12:57:03.842 [WARN ] [caldav.internal.job.EventReloaderJob] - Sardine error while loading calendar entries: Unexpected response (401 - Unauthorized)  com.github.sardine.impl.SardineException: Unexpected response

Here my config with little differences:

> caldavio:Geburtstage:url=https://www.google.com/calendar/dav/<id>@group.calendar.google.com/events
> caldavio:Geburtstage:username=<username> without @gmail.com
> caldavio:Geburtstage:password=<app pw generated>
> caldavio:Geburtstage:reloadInterval=5
> caldavio:Geburtstage:disableCertificateVerification=false
> caldavio:Geburtstage:preloadTime=20000

Has anybody any ideas…

> caldavio:Geburtstage:username=<username> without @gmail.com

in my installation i’m using:

caldavio:mycalendar:username=user@gmail.com

Also the url seems having a different structure.

hi, I also had the HTTP 401 error trying to read my google calendar using the caldav binding.
In my case I had the URL wrong. The correct URL format for me was:
https://www.google.com/calendar/dav/@import.calendar.google.com/events
you can get the calendar id value from the settings of your google calendar, in my case google was showing something like :
abcdef1245@import.calendar.google.com
take the value left from the @ and this should be your calendar-id
good luck !

Hello there, my solution was to set disableCertificateVerification=true. Although the most tutourials say “false”. And in my tests a value for reloadInterval < 5 doesn’t work. Thank yu for your help.

Thanks for the feedback. It make sense, maybe that https certificate verification rely on some system configuration (eg. it has to know the root ca certificate in order to trust the source of the certificate that is checking) so disabling the check remove a potential point of failure. The side effect is that security is lower because without check you can’t really trust the identity of the server you are talking to and you are prone to server impersonation attack. I think that you can bear it :slight_smile:

@querdenker2k:
I’m trying to switch from OH1 to OH2 but I do not get Google OAuthv2 connection up and running.

Do you remember?
We were in contact regarding the same issue in OH1. I got it running using one of your snapshot versions of the addon (1.9.0). Obviously OH 2.2.0 does not support the new URL https://apidata.googleusercontent.com/caldav/v2/<calid>/events out of the box?

https://docs.openhab.org/addons/bindings/caldav-command1/readme.html#google-2-factor-authentication

Thank you @sihui,
I already read that but the documentation seems to be a bit outdated there.
It still references the old Google URL

https://www.google.com/calendar/dav/email@gmail.com/events

If you take a look at CalDAV API Developer's Guide  |  Google Calendar  |  Google for Developers you may see that this URL is deprecated. The new URL

https://apidata.googleusercontent.com/caldav/v2/calid/events

should be already used which now supports OAuth 2.0.

Sorry, can’t tell you any more (nextCloud user :kissing_heart: )

It would be nice if you could correct that or file at least an issue in the docs section.

1 Like

@sihui - I preferred to file issue #668
Got the binding running in my OH2 instance.
The major issue here is that I had to allow “insecure apps” to authenticate and that now username / password is stored in a plain text configuration file.

Hi Thomas.
Can you show your new configuration?
You use this:
https://apidata.googleusercontent.com/caldav/v2/calid/events ?
Greetings,
Markus

Configuration is the same as before with oauth, except you had to allow “insecure apps” in google - at least I did not find another way

How to find calendar ID

The most important in configuration:

caldavio:calendarName:url=https://apidata.googleusercontent.com/caldav/v2/calendar-id/events
caldavio:calendarName:oauth=true
# client_id for OAuth
caldavio:calendarName:username=client-id-for-oauth
# client_secret for OAuth
caldavio:calendarName:password=client-secret-for-oauth

This configuration works properly. Unfortunaly I have to allow insecure apps:

caldavio:GoogleMuellCal:url=https://www.google.com/calendar/dav/<calendar-id>/events
caldavio:GoogleMuellCal:username=<google username>
caldavio:GoogleMuellCal:password=<google user password>
caldavio:GoogleMuellCal:reloadInterval=15
caldavio:GoogleMuellCal:preloadTime=20000
caldavio:GoogleMuellCal:disableCertificateVerification=true

This one should work from my understanding …

caldavio:GoogleMuellCal:url=https://apidata.googleusercontent.com/caldav/v2/<calendar-id>/events
caldavio:GoogleMuellCal:username=<client-id-for-oauth>
caldavio:GoogleMuellCal:password=<client-secret-for-oauth>
caldavio:GoogleMuellCal:oauth=true
caldavio:GoogleMuellCal:reloadInterval=15
caldavio:GoogleMuellCal:preloadTime=20000
caldavio:GoogleMuellCal:disableCertificateVerification=true

… but it results in the following error message:

2018-06-10 21:10:52.854 [WARN ] [caldav.internal.job.EventReloaderJob] - Sardine error while loading calendar entries: Unexpected response (401 - Unauthorized)
com.github.sardine.impl.SardineException: Unexpected response
	at com.github.sardine.impl.handler.ValidatingResponseHandler.validateResponse(ValidatingResponseHandler.java:48) [234:org.openhab.io.caldav:1.12.0]
	at com.github.sardine.impl.handler.MultiStatusResponseHandler.handleResponse(MultiStatusResponseHandler.java:40) [234:org.openhab.io.caldav:1.12.0]
	at com.github.sardine.impl.handler.MultiStatusResponseHandler.handleResponse(MultiStatusResponseHandler.java:35) [234:org.openhab.io.caldav:1.12.0]
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:218) [234:org.openhab.io.caldav:1.12.0]
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:160) [234:org.openhab.io.caldav:1.12.0]
	at com.github.sardine.impl.SardineImpl.execute(SardineImpl.java:962) [234:org.openhab.io.caldav:1.12.0]
	at com.github.sardine.impl.SardineImpl.list(SardineImpl.java:417) [234:org.openhab.io.caldav:1.12.0]
	at com.github.sardine.impl.SardineImpl.list(SardineImpl.java:409) [234:org.openhab.io.caldav:1.12.0]
	at com.github.sardine.impl.SardineImpl.list(SardineImpl.java:386) [234:org.openhab.io.caldav:1.12.0]
	at org.openhab.io.caldav.internal.job.EventReloaderJob.loadEvents(EventReloaderJob.java:246) [234:org.openhab.io.caldav:1.12.0]
	at org.openhab.io.caldav.internal.job.EventReloaderJob.execute(EventReloaderJob.java:137) [234:org.openhab.io.caldav:1.12.0]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [107:org.eclipse.smarthome.core.scheduler:0.10.0.oh230]
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [107:org.eclipse.smarthome.core.scheduler:0.10.0.oh230]

I also get the same 401 unauthorized error with using the v2 API and OAuth. I am using the latest openHAB 2.3 snapshot. Is there a current workable solution using the Google v2 API are we stuck with v1 and insecure apps for the time being?

1 Like

Any update on this topic?

I also have problems with the 401 error.
The error appears every minute but the config is set to every 60minutes.

caldavio.cfg

Abfall:url=https://www.google.com/calendar/dav/<calenderID>@group.calendar.google.com/events
Abfall:username=<username-without-@gmail.com>
Abfall:password=<password>
Abfall:reloadInterval=60
Abfall:preloadTime=20000
Abfall:disableCertificateVerification=true
Abfall:timeZone=Europe/Berlin

The documentation says we need a caldavio: prefix but many users and every tutorial says it´s buggy.

caldavCommand.cfg and caldavPersonal.cfg are not configured.

Abfall.items

String calAbfallTonne "Tonne [MAP(muell.map):%s]" <tonne> {caldavPersonal="calendar:Abfall type:EVENT eventNr:1 value:NAME"}
String calAbfallMieter "Tonne [%s]" <tonne> {caldavPersonal="calendar:Abfall type:EVENT eventNr:1 value:DESCRIPTION"}
String calAbfall "Nächste Leerung [%s]" <tonne>
DateTime calAbfallDate "Datum der Abholung [%1$td.%1$tm.%1$tY]" <calendar> {caldavPersonal="calendar:Abfall type:EVENT eventNr:1 value:START"}

Logfile warning:

2018-11-27 12:39:08.840 [WARN ] [caldav.internal.job.EventReloaderJob] - Sardine error while loading calendar entries: Unexpected response (401 - Unauthorized)
com.github.sardine.impl.SardineException: Unexpected response
2018-11-27 12:40:08.805 [WARN ] [caldav.internal.job.EventReloaderJob] - Sardine error while loading calendar entries: Unexpected response (401 - Unauthorized)
com.github.sardine.impl.SardineException: Unexpected response
2018-11-27 12:41:08.806 [WARN ] [caldav.internal.job.EventReloaderJob] - Sardine error while loading calendar entries: Unexpected response (401 - Unauthorized)
com.github.sardine.impl.SardineException: Unexpected response
2018-11-27 12:42:08.798 [WARN ] [caldav.internal.job.EventReloaderJob] - Sardine error while loading calendar entries: Unexpected response (401 - Unauthorized)
com.github.sardine.impl.SardineException: Unexpected response
	at com.github.sardine.impl.handler.ValidatingResponseHandler.validateResponse(ValidatingResponseHandler.java:48) [227:org.openhab.io.caldav:1.12.0]
	at com.github.sardine.impl.handler.MultiStatusResponseHandler.handleResponse(MultiStatusResponseHandler.java:40) [227:org.openhab.io.caldav:1.12.0]
	at com.github.sardine.impl.handler.MultiStatusResponseHandler.handleResponse(MultiStatusResponseHandler.java:35) [227:org.openhab.io.caldav:1.12.0]
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:218) [227:org.openhab.io.caldav:1.12.0]
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:160) [227:org.openhab.io.caldav:1.12.0]
	at com.github.sardine.impl.SardineImpl.execute(SardineImpl.java:962) [227:org.openhab.io.caldav:1.12.0]
	at com.github.sardine.impl.SardineImpl.list(SardineImpl.java:417) [227:org.openhab.io.caldav:1.12.0]
	at com.github.sardine.impl.SardineImpl.list(SardineImpl.java:409) [227:org.openhab.io.caldav:1.12.0]
	at com.github.sardine.impl.SardineImpl.list(SardineImpl.java:386) [227:org.openhab.io.caldav:1.12.0]
	at org.openhab.io.caldav.internal.job.EventReloaderJob.loadEvents(EventReloaderJob.java:246) [227:org.openhab.io.caldav:1.12.0]
	at org.openhab.io.caldav.internal.job.EventReloaderJob.execute(EventReloaderJob.java:137) [227:org.openhab.io.caldav:1.12.0]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [107:org.eclipse.smarthome.core.scheduler:0.10.0.oh230]
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [107:org.eclipse.smarthome.core.scheduler:0.10.0.oh230]

The credentials are correct and i´m able to download the entries with a browser.

kind regards
Michael

Hi,

Sorry, i am not using the Google calendar. I Just tested it maybe 2 years ago.
The warn Message appears every Minute because of the failure.
Your configuration Looks good. Isn’t Somebody Here who is using caldav with Google?

Hi,

I configured the binding with Google a year ago and it worked with some restriction.
Allow insecure apps in Google configuration.
The configuration is shwon below:

addons.cfg:

binding = caldav-command1, caldav-personal1

caldavPersonal.cfg

caldavPersonal:usedCalendars=Rollladensteuerung

caldavCommand.cfg

caldavCommand:readCalendars=Rolladensteuerung

caldavio.cfg

caldavio:Rolladensteuerung:url=https://www.google.com/calendar/dav/<id>@group.calendar.google.com/events
caldavio:Rolladensteuerung:username=<username-without-@gmail.com>
caldavio:Rolladensteuerung:password=<password>
caldavio:Rolladensteuerung:reloadInterval=1
caldavio:Rolladensteuerung:preloadTime=18720
caldavio:Rolladensteuerung:disableCertificateVerification=true
caldavio:timeZone=Europe/Berlin

As I recall, a warning or error appeared after shifting calender entries.

Hi there,

i use this ol topic because I have an issue with the caldav binding.

I configured it and it worked for two days. Now I get an 401 error. But not with the calender I want to use.
I had serveral configurations and I deleted all exept one. This is working. But the errors are from an old configuration that I dont use.
I cleaned the cache with no result.and a restart didnt solve the problem as well.

Has someone an idea?

I had the same problem. Tried to fix it by the hints in the forum. It was not a OH / CALDAV configuration problem but a Google security issue.
I had to allow less secure Apps in my google accout https://myaccount.google.com/lesssecureapps

Now everything is working fine … but with less security