The Vera Community forums have moved!

Advanced => Plugins & Plugin Development => Programming => Google Calendar Switch => Topic started by: powisquare on January 25, 2016, 11:53:07 am

Title: iCal
Post by: powisquare on January 25, 2016, 11:53:07 am
Hello Stuart,

Just discovered the calendars I use are in fact ical feeds. Would it still be possible to set GCal up, perhaps as a read only instance? I can get the info <iframe to </iframe> just will not be able to share. Thanks!
Title: Re: iCal
Post by: Stuart on January 26, 2016, 08:40:35 am
The short answer is 'probably'.  The slightly longer answer is it depends somewhat on how the iCal was set up.   Take a look at the instructions in the very top post.
Title: Re: iCal
Post by: powisquare on January 26, 2016, 12:17:50 pm
Thanks Stuart. I am unable to Share the calendar and thus link to google service account. Is this a problem or can I forget this step? I seem to be stuck in bypass mode but the link works if i paste into a browser.
Title: Re: iCal
Post by: Stuart on January 26, 2016, 01:09:51 pm
Stuck in bypass mode ?  Should only happen if the plugin is not armed.
Title: Re: iCal
Post by: powisquare on January 26, 2016, 01:24:43 pm
Progress! Now getting Access or Calendar Error .. Thanks for your patience Stuart.
Title: Re: iCal
Post by: powisquare on January 26, 2016, 01:36:29 pm
Is there a time limit for Gcal to get a response? I am on satellite broadband and with this weather it is quite slow.
Title: Re: iCal
Post by: Stuart on January 26, 2016, 04:32:27 pm
The standard timeout is 30s which should be more than enough.

The "access or calendar error" WAS a high level error message that I've removed in recent patches (but not in the latest formal release) as it was over writing the actual error message.

Try this version and we should get close to seeing the real issue.  Note that we may have to get a log file as well.

EDIT: Attachment Removed
Title: Re: iCal
Post by: powisquare on January 26, 2016, 05:21:07 pm
Yup still no luck. error 404. Tried the Miami Heats also and had the same result. Even remembered to change "&" too!
Title: Re: iCal
Post by: Stuart on January 26, 2016, 11:34:41 pm
I suspect you have a typo or something. Error 404 usually means that the url could not be found.

Try the following:
(1) make sure the plugin is armed
(2) cut and paste this into the Calendar ID input on the Control Tab

<iframe src="https://www.google.com/calendar/htmlembed?src=nba_14_%254diami%2B%2548eat%23sports%40group.v.calendar.google.com
&ctz=America/Denver" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>

(3) click on "Set"

You mentioned above that you were using an iCal -- the plugin does not use credentials to get at an ical (with the url in a form something like https://www.abc123.com/calendar/ical/....).  This is because the iCal calendar must be public in order to be used.  This is DIFFERENT than if you access an iCal through your google calendar in which case it is given an alias url by google and accessed in the normal manner (with credentials).


If you IM me the actual Calendar url's you are using (assuming an iCal) - I can take a look.
Title: Re: iCal
Post by: powisquare on January 27, 2016, 03:49:50 am
Thanks for this Stuart. Your link appears to work showing no more events today. I have noticed a popup on google calendar advising my calendar is not public. I have PMd you with the link as it does open in a browser.
Title: Re: iCal
Post by: Stuart on January 27, 2016, 02:44:54 pm
So several things to note.  If you calendar is in fact a google calendar (or linked to another calendar -- even an iCal) you need to share this calendar with your service account.  This is the case with the url's you shared via IM.  The instructions for sharing are in the service account instructions in the link below (first post of the main topic).  In your case - the 404 error suggest that you have not shared the calendar with the service account or you have not created the service account properly.  I just went through the instructions and except for a typo (which I fixed) - the instructions are accurate.  It's likely quicker for you to go back and redo these steps.

If your calendar is just some ordinary iCal (not linked via google) then there are no credentials involved (but obviously that calendar would have to be public).

I just added a test credentials file and test calendar ID that can be used to prove that the plugin is working properly.  See the Debugging section on the first post.

http://forum.micasaverde.com/index.php?topic=26692.msg189513#msg189513
Title: Re: iCal
Post by: powisquare on January 27, 2016, 04:13:09 pm
Going back to my original post am unsure if I am able to share this calendar. Thanks for you time, I will have to have a rethink.
Title: Re: iCal
Post by: Stuart on January 27, 2016, 04:50:34 pm
Can you see your calendar in calendar.google.com ? 
Title: Re: iCal
Post by: powisquare on January 27, 2016, 05:37:33 pm
Yes I can. I have logged out of google and the calendar displays correctly.
Title: Re: iCal
Post by: Stuart on January 28, 2016, 06:05:46 pm
I just thought of something that MAY be to do with the calendar url you are trying to access.  I unfortunately deleted your previous IM.  Would you mind resending ?  It's POSSIBLE that there is a google url variant that I am not handling.  It's been trial and error since there does not seem to be a published list of all the variations anywhere.
Title: Re: iCal
Post by: powisquare on January 29, 2016, 06:23:32 am
Will do.
Title: Re: iCal
Post by: Stuart on January 29, 2016, 11:13:29 am
The url format for your calendar was NOT one of the forms that I knew about.  I'm rethinking how best to parse the google url.  In the meantime I added this form to the code and the patch file can be found here:

http://forum.micasaverde.com/index.php/topic,26692.msg267038.html#msg267038

Basically -- because you are using google to get at a non-google calendar, google uses a slightly different url than normal.

So try the patch if everything is ok it should now work.  If you still get an error it's likely a http 404 error (which is the one I get when I try your url) because you do not have access to the calendar (either through settings on the calendar in google or credentials are not set correctly).

In any case - we are getting closer ....   :D
Title: Re: iCal
Post by: powisquare on January 29, 2016, 12:11:35 pm
Yes, I do appear to be seeing 404 error after updating. Just to recap - I have not set any credentials as I am unable to share (as far as I know) the calendar to the Google Service Account email. I do not know if this will affect what we are trying to achieve even though the calendar link opens a calendar without requiring authentication.
Title: Re: iCal
Post by: Stuart on January 29, 2016, 04:47:52 pm
The http 404 error code can mean (usually) one of two things (1) that the url cannot be found or (2) that you do not have permission to access it.

In this case I suspect it's a permission issue.  So now the question is whether it's at the google end or at the ical end.

Can you see and access the calendar in google ?  In an earlier reply you said "Yes I can. I have logged out of google and the calendar displays correctly."  but it was not clear to me if you meant that you were accessing the ical directly or if it was displaying in your google calendar.

If it does not display - then it's a good guess that the problem is at the ical end.  How are the permissions set in your ical -- is it public ?  If it is - and you want to share the ical link via IM I can see if I can access from my system.

Also - if it is public - have you tried putting in the ical link directly into GCal (it will work with some ical calendars but not all as ical is not standardised too well)

have a look in https://calendar.google.com/calendar/syncselect  does your calendar show up as shared and read only ?
Title: Re: iCal
Post by: Stuart on January 30, 2016, 12:58:07 am
I just tried getting an iCloud calendar to show up in google calendar and guess what .... error 404.  So I think the problem may be at the google end.  There are some posts on the web talking about issues.

I'll see if I can make sense of it over the weekend.
Title: Re: iCal
Post by: powisquare on January 30, 2016, 06:32:43 am
The http 404 error code can mean (usually) one of two things (1) that the url cannot be found or (2) that you do not have permission to access it.

In this case I suspect it's a permission issue.  So now the question is whether it's at the google end or at the ical end.

Can you see and access the calendar in google ?  In an earlier reply you said "Yes I can. I have logged out of google and the calendar displays correctly."  but it was not clear to me if you meant that you were accessing the ical directly or if it was displaying in your google calendar.

I copied the html link in google calendar, logged out, pasted into address bar. This opened up calendar.google.com. Please feel free to try the link - it is not sensitive data.

If it does not display - then it's a good guess that the problem is at the ical end.  How are the permissions set in your ical -- is it public ?  If it is - and you want to share the ical link via IM I can see if I can access from my system.

It is not public. I did visit the syncselect page and ticked the box to this shared calendar

Also - if it is public - have you tried putting in the ical link directly into GCal (it will work with some ical calendars but not all as ical is not standardised too well)

have a look in https://calendar.google.com/calendar/syncselect  does your calendar show up as shared and read only ?

Yes.
Title: Re: iCal
Post by: powisquare on February 07, 2016, 07:00:22 pm
Hello - did you have any more luck with this?
Title: Re: iCal
Post by: Stuart on February 07, 2016, 11:58:46 pm
I've been doing quite a bit and in the middle of writing up some notes (see draft incomplete below) .  Also making some code changed for Direct method  iCal -- because of some underlying issues in the Lua libraries - that's pretty well done.  Note that this does not affect calendars from google like the one you sent the url for.

One thing that I noted is that the url you sent to me is not public -- so I could not see it -- that may be part of the issue if the permissions are incorrect at the google end.  i.e. given the url you sent gcal will treat it like any google calendar.  Below I say "you need to set up google credentials in the normal way." -- but I still need to figure out exactly what that means because it's not clear what google expects in this circumstance.  That's the next step to figuring this out.

Can you send me the public direct url to the ical ?  Not the one created by google but the one that you input into google.  I can troubleshoot on that come wednesday (traveling in the meantime)

The following notes are ? to the best of my knowledge ? accurate BUT they are based on limited use of iCal and may contain errors.
Basically ? there are two ways GCal can access an iCal:
1.   Directly.  This method uses a direct link to an iCal that bypasses Google calendar
a.   The GCal plugin has some limitations on direct iCal use.  Not all iCal can be interpreted correctly. This is because the iCal specification allows for variations in format ? not all of these variations are handled by GCal.
b.   This is a direct link to your iCal so changes that you make to your iCal will show up immediately.
c.   The iCal must be public.
d.   The calendar information will not show up in the calendar tab of the plugin
e.   There are no credentials required.


2.   Through Google Calendar.
a.   If  google calendar can display the iCal correctly then GCal can.
b.   You are creating a subscription from google calendar to an iCalendar.  Google only updates this subscription from time to time (every 12 hrs. ?).  Changes that you make to your iCal may not show up in google (and hence GCal) for a while.
c.   The iCal must be public for google to see it.
d.   The calendar information will show up in the calendar tab of the plugin
e.   You need to set up google credentials in the normal way.

The Direct Method
GCal will attempt direct access to iCal by looking for ?.ics? or ?.ical? or ?.iCloud? in the url that you input as the Calendar ID.  It then treats the calendar as public and does not use any google credentials.  For example:
https://www.calendarlabs.com/templates/ical/International-Holidays.ics
To test if your url is likely to work, try opening the url into a browser.  If it downloads a .ics file ? then it?s likely good.  Check by opening the .ics file in a text editor.  The top few lines should look something like this:

BEGIN:VCALENDAR
PRODID:-//Calendar Labs//Calendar 1.0//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:International Holidays
X-WR-TIMEZONE:America/New_York
BEGIN:VEVENT


If it does not have BEGIN:VCALENDAR and VERSION:2.0 then it?s NOT an iCal.  If it does then it should be an iCal.

Through Google Calendar

Yet to write this bit up but intend for it to be a step by step setup for an iCal being accessed by google.

Title: Re: iCal
Post by: powisquare on February 08, 2016, 04:57:53 am
Tried the Direct Method which does indeed download a file containing BEGIN:VCALENDAR,
VERSION:2.0, PRODID ... have sent you the link.
Title: Re: iCal
Post by: Stuart on February 08, 2016, 04:55:12 pm
So the direct method does not currently work on all iCal's because of the lua library issue that I mentioned.  I'm working on it .....

However the "through google calendar" method seems to work perfectly !!

I created a calendar in google using your url
Other Calandars --> Add by url
Insert the ical url
Make the calendar publicly accessible? worked both ways
--> Add Calendar

I then went to Settings --> Calendar --> [your calendar] and got the embedded Calendar Link <iframe .......... </iframe>

put it in as the Calendar ID in the plugin and ..... (tada).

you should try this using the test credentials I posted on the main thread.   I'm now convinced that your credentials are not set up correctly.
Title: Re: iCal
Post by: Stuart on February 11, 2016, 02:09:41 pm
@ powisquare

You can try this patch with the direct iCal url if you like.  Seems to be working fine.

Make sure you set the calendar ID again as there was an error encoding certain iCal url's (Direct) that I have corrected.

Did you get the google variant working ?

Edit: Patch removed as it's included in the official version
Title: Re: iCal
Post by: powisquare on February 12, 2016, 05:19:13 am
Have had a bit of trouble (credentials) but seems to be working now! Will be away for a week so shall look at this in more depth on my return. Kind Regards.
Title: Re: iCal
Post by: powisquare on May 12, 2016, 05:20:51 am
Good news. I started again again created a new credential with my personal calendar as there is no way of sharing the ical I am using. I have then used the ical Calendar Link and it works.

Is it possible for the app to look 2 days out instead of one and do you know of any pleg examples out there using your app I might be able to refer to?
Title: Re: iCal
Post by: Stuart on May 12, 2016, 11:36:43 am
Good news. I started again again created a new credential with my personal calendar as there is no way of sharing the ical I am using. I have then used the ical Calendar Link and it works.

Is it possible for the app to look 2 days out instead of one and do you know of any pleg examples out there using your app I might be able to refer to?

Good to hear that it is working for you.   Are you on the latest version from the marketplace ?   It has some additional capabilities and changes that you should upgrade to (so I can continue to support).  I cannot remember if the patch version you were working with includes this - but the latest version in the marketplace has an additional parameter gc_ExtraDays (default is 0) So to look 1 additional day ahead you set it to 1.

I will have a slightly newer version in the marketplace in the next day or 2 (has better handling of initial configuration mistakes).  You may want to to wait for that.

For PLEG - I will have a look to see what examples I have.  I do not know if others do.  You should post a request in the main GCal and PLEG forums.

Good Luck
Title: Re: iCal
Post by: Stuart on May 12, 2016, 02:20:21 pm
If you are already on V2.0 you can get the next version (2.1) without waiting for the marketplace to update by using the following:

http://<your vera IP>:3480/data_request?id=action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=CreatePlugin&PluginNum=7016&Version=31461

If you are NOT on V2.0 already - then be sure to follow the upgrade instructions here:
http://forum.micasaverde.com/index.php/topic,26692.msg276087.html#msg276087
Title: Re: iCal
Post by: powisquare on December 29, 2016, 12:59:07 pm
So the calendar has been up and running in gcal3 for a while now which is great. I have installed it on another box (same version 2.5)and am trying to access a similar calendar to the one that works. ie it comes from the same 3rd party source in the same format. Am getting a 404 credential error. I am using the same credential file as the calendar that works. Apologies for the cross posting but probably should have started here to begin with.

Title: Re: iCal
Post by: Stuart on December 29, 2016, 01:04:34 pm
See my prior post in the main forum.   You are using a GOOGLE calendar ID therefore you need to apply the credentials to the google calendar.   The fact of the underlying calendar info comes from an  iCal is irrelevant in this situation.
Title: Re: iCal
Post by: powisquare on December 29, 2016, 02:23:13 pm
Sorry .. totally confused. I do not know how to apply credentials to the google calendar. Don't see an option for it or for sharing - am I missing something?

These are the two calendar links. The top one works in both Vera boxes. The second gives me the 404 error.

<iframe src="https://calendar.google.com/calendar/embed?src=boliagvia0dbk3njt530ljvvjuu8270p%40import.calendar.google.com&ctz=Europe/London" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>

<iframe src="https://calendar.google.com/calendar/embed?src=jshm8k9j7u6pjqb3jho7vp6lg4fvhjvk%40import.calendar.google.com&ctz=Europe/London" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
Title: Re: iCal
Post by: Stuart on December 29, 2016, 05:37:44 pm
Open this document from the main post:
Google V3 API Service Account V3.pdf

For the calendar that does not work -- perform the steps from:
"BUT ? you also need to:"

Title: Re: iCal
Post by: powisquare on December 30, 2016, 05:27:32 am
I don't believe I am able to do the following (there is no option to share) and have attached a screenshot of what I am seeing:-

Next click on Share this Calendar
On the section that says ?Share with specific people? Add the client-email from the
step above. Change the permission to ?Make Changes to Events?
Click on Add Person
You should now see the client_email listed like this

What puzzles me is that I was not able to complete this step for the calendar that is working either.
Title: Re: iCal
Post by: Stuart on January 03, 2017, 03:27:28 pm
The problem is permissions - the bit that says:
Anyone can: See nothing
You can: See all event details.

This is because GCal is accessing the calendar programmatically and needs specific credentials (which it does not have).  It's trying to access the calendar as "Anyone" and it's working ...  you CAN "See nothing"  :D 

Try just putting in the source iCal url in as the Calendar id.  Your iCal is public so that ought to work.  i.e.

https://marshwoodmanor.checkfront.co.uk/view/bookings/ics/?id=<..snip..>&iid=7&m=24
Title: Re: iCal
Post by: powisquare on January 09, 2017, 05:17:28 am
You are quite right of course - the working calendar 'Anyone can See all events'.

I have spent a week trying to figure out how I managed to alter this sharing permission. I looked at https://calendar.google.com/calendar/syncselect and the working calendar was checked and the others not. I have since checked all remaining calendars but they still all read 'Anyone can see nothing'.

Sadly the source ical does not seem to work.
Title: Re: iCal
Post by: Stuart on January 09, 2017, 12:21:52 pm
You are quite right of course - the working calendar 'Anyone can See all events'.

I have spent a week trying to figure out how I managed to alter this sharing permission. I looked at https://calendar.google.com/calendar/syncselect and the working calendar was checked and the others not. I have since checked all remaining calendars but they still all read 'Anyone can see nothing'.

Sadly the source ical does not seem to work.

I'm surprised since your source iCal url works fine in my plugin.  Your calendar is publicly available .......

I will PM you your url so that there is no confusion.
Title: Re: iCal
Post by: powisquare on January 14, 2017, 04:52:50 pm
Thanks Stuart - PM received. I replaced the working calendar ID with the source url provided and get "No iCal events found today". Put the iframe one back in and it's working.
Title: Re: iCal
Post by: powisquare on January 26, 2017, 05:57:40 am
Got there in the end. To share a third party  ical with google and when using "add by url" remember to check the "Make the calendar publicly accessible?" box so that "Anyone can: See all event details".