来自php的动态.ics未在Google日历中更新

时间:2011-09-01 09:27:44

标签: php google-calendar-api icalendar

我一直在尝试在php中创建一个.ics页面,该页面将通过“按URL添加”添加到Google日历中,以便我从数据库中检索事件并将其显示在日历中。

我已经在SO上搜索了一段时间,发现了另一篇非常有用的帖子,但我现在遇到的障碍似乎并没有影响那些代码相似的人。可以找到帖子here

所以,我的问题是我似乎无法让Google日历更新我的页面,就好像它已在日历中缓存了页面一样。因此,当我向页面添加另一个VEVENT时,它不会更新日历。

创建文件时,它会为* .ics文件生成正确的格式。格式如下所示。

如果我直接进入该页面,系统会提示您下载该文件,该文件可以导入GC,如果我将相同的代码添加到其他页面,例如更改 cal的页面名称。 php cal2.php ,会让GC读取所有事件,而当我只是添加相同的URL时,它不会接收对文件所做的任何更改。

任何人都知道为什么不更新?

其他有类似问题的人通过在他们的VEVENT中添加UID来解决这个问题,这对我来说没有解决这个问题......

生成格式

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:17d88c861131ec62f18835cdd4eb7d0c@yourhost.test
DTSTAMP:20110901T092002Z
DTSTART:20110925T170000Z
DTEND:20110928T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
BEGIN:VEVENT
UID:00813115d1a2d21447eb11ded3ba9020@yourhost.test
DTSTAMP:20110901T092002Z
DTSTART:20110929T170000Z
DTEND:20110930T035959Z
SUMMARY:Camping Trip
END:VEVENT
BEGIN:VEVENT
UID:1f18d85fe516d684536129ed066e7d4f@yourhost.test
DTSTAMP:20110901T092002Z
DTSTART:20110914T170000Z
DTEND:20110915T035959Z
SUMMARY:Testing new Event
END:VEVENT
END:VCALENDAR

使用的代码

<?php
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=\"calendar.ics\"");
echo "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:20110925T170000Z
DTEND:20110928T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:20110929T170000Z
DTEND:20110930T035959Z
SUMMARY:Camping Trip
END:VEVENT
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:20110914T170000Z
DTEND:20110915T035959Z
SUMMARY:Testing new Event
END:VEVENT
END:VCALENDAR";
?>

3 个答案:

答案 0 :(得分:2)

我认为您应该使用 VEVENT 中的 SEQUENCE 属性,并且每次更改后都应增加

答案 1 :(得分:2)

csanyigabor是正确的。此外,您必须确保UID是相同的,以便应用程序匹配事件。 这里的问答在于取消,但原则是相同的 How to cancel an calendar event using ics files?

答案 2 :(得分:0)

@csanyigabor是对的,所以@anmari也是如此,但我接受了一些其他提示。在构建ICS文件时,如anmari所说,确保每次进行同步时,您的UID都是一致的。我已经根据用户提供的一些文本创建了一个哈希(糟糕,糟糕的主意。5年前,当我构建它时,我自己感到羞耻)。

如果你去这里 - &gt; https://tools.ietf.org/html/rfc5545(以及此处的一些更新点 - &gt; https://tools.ietf.org/html/rfc7986)它提供了一些有用的内容。特别是3.8.7.4. Sequence Number,它概述了新序列的标准。

  Description: When a calendar component is created, its sequence
  number is 0.  It is monotonically incremented by the "Organizer's"
  CUA each time the "Organizer" makes a significant revision to the
  calendar component.

3.8.4.7. Unique Identifier

中对UID的说法也很有帮助
  Description:  The "UID" itself MUST be a globally unique identifier.
  The generator of the identifier MUST guarantee that the identifier
  is unique.  There are several algorithms that can be used to
  accomplish this.  A good method to assure uniqueness is to put the
  domain name or a domain literal IP address of the host on which
  the identifier was created on the right-hand side of an "@", and
  on the left-hand side, put a combination of the current calendar
  date and time of day (i.e., formatted in as a DATE-TIME value)
  along with some other currently unique (perhaps sequential)
  identifier available on the system (for example, a process id
  number).  Using a DATE-TIME value on the left-hand side and a
  domain name or domain literal on the right-hand side makes it
  possible to guarantee uniqueness since no two hosts should be
  using the same domain name or IP address at the same time.  Though
  other algorithms will work, it is RECOMMENDED that the right-hand
  side contain some domain identifier (either of the host itself or
  otherwise) such that the generator of the message identifier can
  guarantee the uniqueness of the left-hand side within the scope of
  that domain.

Example: The following is an example of this property:

 UID:19960401T080045Z-4000F192713-0052@host1.com