导入.ics文件时出现Google日历错误 [英] Google Calendar errors on importing .ics file

查看:101
本文介绍了导入.ics文件时出现Google日历错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让我的订阅日历与Google日历一起使用.以下URL可以在Outlook和Apple Calendar(iCal)上正常使用,但是我从Google收到错误消息:您提供的地址未包含有效iCal或GData格式的日历."

I'm having a hard time getting my subscription calendar to work with Google Calendar. The following URL works correctly with Outlook and Apple Calendar (iCal), but I get an error from Google - "The address that you provided did not contain a calendar in a valid iCal or GData format."

我的URL通过了以下验证器的验证(icalvalid.cloudapp.net/和severinghaus.org/projects/icv/)

My URL passes validation on the following validators (icalvalid.cloudapp.net/ and severinghaus.org/projects/icv/)

任何人都可以提供任何想法吗?这是网址: https://beta.vcallboard.com /calls/exportcalendar.php?userID=Mg%3D%3D&token=MjB6N2E0OTk%3D

Can anyone provide any idea what is wrong? Here is the URL: https://beta.vcallboard.com/calls/exportcalendar.php?userID=Mg%3D%3D&token=MjB6N2E0OTk%3D

我已经尝试过的理论: -无法在https上运行-(我将.ics文件保存并上传为服务器根目录中的文件,并且该URL有效-似乎与自动生成有关) -某些字段的空白值无效(如果我将其上传为.ics文件,则可以使用该值)

Theories I've already tried: - doesn't work over https - (I saved and uploaded the .ics file as a file in my server root and that URL worked - seems it has something to do with the auto-generation) - blank values for some fields aren't valid (it works if I upload it as a .ics file)

推荐答案

我对我的问题感到困惑,因为我可以手动导入脚本输出的.ics文件,并且Google日历可以毫无问题地读取该文件.因此,我认为我对iCal文件的实际格式没有任何问题-我认为这与标头或某些服务器配置有关.所以我做了一些实验...

I was baffled by my problem because I could manually import the .ics file that was output by my script and it was read by Google Calendar with no problem. So i figured I didn't have a problem with the actual format of the iCal file - I figured it had to be a problem with the headers or some server config. So I did a few experiments...

长话短说,通过执行以下操作,我可以在Google日历上使用它:

Long story short, I was able to get this to work on Google Calendar by doing the following:

  1. 使用所有iCal数据加载变量,从数据库中提取数据,站点常量等.请确保使用\r\n在验证器中进行更好的验证.

  1. Load up a variable with all the iCal data, pulling from the database, site constants etc. Make sure to use \r and \n for better validation in the validators.

$iCal = "BEGIN:VCALENDAR\r
VERSION:2.0\r
PRODID:-//VirtualCallboard//".SITENAME."//EN\r
CALSCALE:GREGORIAN\r
METHOD:PUBLISH\r";
while ($r=mysql_fetch_assoc($result))
{
    // i do a bunch of stuff here to get variables ready for the output
    $iCal .= "BEGIN:VEVENT\r
DTSTAMP:".gmdate("Ymd\THis\Z")."\r
DTSTART:".date("Ymd\THis\Z", strtotime($r[tdstart]))."\r
DTEND:'.date("Ymd\THis\Z",   strtotime($r[tdend]))."\r
SUMMARY:$r[title]\r
UID:$r[callid]@".$_SERVER['HTTP_HOST']."\r
DESCRIPTION:$r[notes].\r
LOCATION:$r[location_name].\r
STATUS:CONFIRMED\r
END:VEVENT\r\n";
}
$iCal .= "END:VCALENDAR";

  • 转义特殊字符(我现在所知道的都是逗号).然后(这是秘密)-使用file_put_contents将iCal变量中的字符串写入缓存目录中具有.ics扩展名的文件中.

    //escape special characters.
    $iCal = str_replace(",","\,",$iCal);
    
    //output to a file
    $filename = 'site/cache/'.date("YmdHis").'.ics';
    file_put_contents($filename,$iCal);
    

  • 调用标题:

  • Call the headers:

    //set correct content-type-header
    header("Content-Type:text/calendar");
    header("Content-Disposition:inline;filename=my_ical.ics");
    

  • 使用file_get_contents从文件中读取.ics数据,并将其输出到浏览器.

  • Use file_get_contents to read the .ics data back out of the file and output it to the browser.

    print file_get_contents($filename);
    

  • 清理我在缓存目录中创建的.ics文件.

  • cleanup the .ics file I created in my cache directory.

    unlink($filename);
    exit;
    

  • 由于某种原因(我无法解释),这使得相同的文件在Google日历中可以正常工作.因此,它与Outlook,Google日历和Apple日历兼容.

    For some reason, which I can't explain, this made the exact same file work in Google Calendar. So this is compatible with Outlook, Google Calendar, and Apple Calendar.

    这篇关于导入.ics文件时出现Google日历错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆