开发者

Why won't Google Calendar load my dynamically generated ICS file?

开发者 https://www.devze.com 2023-03-14 05:14 出处:网络
I\'ve been given the task of creating an ICAL feed of conference calls for members of our organization. I created a handler in ASP.NET that loops through our database, gets the call data from the data

I've been given the task of creating an ICAL feed of conference calls for members of our organization. I created a handler in ASP.NET that loops through our database, gets the call data from the database, and creates output that appears valid to me based on what I've read of the ICAL format, and the examples I've seen/disassembled.

Outlook 2007 reads the resulting output and displays the calendar, no problem (screenshot here shows how it renders).

30 Boxes also has no problem with it. (see test here).

But when I try to load the same output into Google Calendar, I get the message "We could not parse the calendar at the url requested":

Why won't Google Calendar load my dynamically generated ICS file?

What's wrong with my output that's c开发者_JAVA百科ausing Google to reject it? You can see the temporary data I'm testing with at this URL: http://www.joshuacarmody.com/temp/icaltest.ics. This is a snapshot of the output from my .ASHX file, unaltered except the phone numbers and passcodes have been sanitized.

Edit with additional Info:

I just tried the following

  1. Created a copy of my test file called "icaltest-1googevent.ics"
  2. Deleted all the VEVENT data from the file
  3. Exported one of my Google calendars to ICS
  4. Copied one VEVENT from Google's exported data into my test file
  5. Attempted to subcribe to icaltest-1googevent.ics in Google Calendar.

I still got an error message. So I'm guessing the issue isn't with my VEVENT data, but with something else about the file. Maybe there's something wrong with my VCALENDAR definition?


the severinghaus ics validator seems to think there is something funny ( a ? ) before the BEGIN CALENDAR

http://severinghaus.org/projects/icv/?url=http%3A%2F%2Fwww.joshuacarmody.com%2Ftemp%2Ficaltest.ics

In my testing google was a lot fussier/rigourous/pedantic - once you get it working with the validator and google it should work in most places.


After lots of trial-and-error, and comparing my output with Google's, I got it working. There were a few problems with my ICS file:

  • Unescaped characters (I didn't know I had to escape commas!)
  • Inconsistent line return characters. They didn't show up in my text editor, but I had to use .NET's String.remove() to remove "\r" from my output to get Google to recognize it
  • The file was missing VCALENDAR:END. Apparently Outlook doesn't much care. Google does.


I had not one, but three funny characters before the BEGIN:VCALENDAR, decimal codes 239, 187, 191.

I found them thanks to the severinghaus.org link above, thanks!

It turns out they're a prefix called BOM in UTF-8, you can read up on it here: http://en.wikipedia.org/wiki/UTF-8#Byte_order_mark

Google doesn't handle this, but after stripping these three characters from the file and uploading to the server, I was able to susbribe to that calendar in Google Calendar (from URL).

I hope this helps someone passing by this page in the future...


I had similar problem until I realised that opening the generated .ics file in Notepad++ wasn't in UTF-8. I was using a method to convert my string to a byte array, but wasn't using an encoder for this, so no matter what content headers I used, the file would never be generated using UTF-8. This simple fix resolved the UTF-8 generation and Google is now happy with my feed:

var utf8 = Encoding.UTF8;
byte[] utfBytes = utf8.GetBytes(myString);
myString= utf8.GetString(utfBytes, 0, utfBytes.Length);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号