使用谷歌日历检查假期

时间:2013-05-28 10:09:47

标签: php google-calendar-api

我正在试图弄清楚如何针对谷歌日历验证特定日期(比方说今天),我需要构建一个功能来检查今天是否是假日。

我可以在https://www.google.com/calendar/htmlembed?src=thai@holiday.calendar.google.com看到实际的日历 但我想找出一种通过API检查事件的具体日期的方法

如果有人能指出我的话,我会更高兴。

1 个答案:

答案 0 :(得分:1)

首先,您需要这样的日历地址:https://support.google.com/calendar/answer/37103?hl=en

然后将日历条目加载到数组中:

$xml = simplexml_load_file("path/to/calendar");
$xml->asXML();
$holidays = array();
foreach ($xml->entry as $entry){
  $a = $entry->children('http://schemas.google.com/g/2005');
  $when = $a->when->attributes()->startTime;

  $holidays[(string)$when]["title"] = $entry->title;
}

现在检查日历中是否存在日期

if(is_array($holidays[date("Y-m-d")]))
    echo "holiday";
else 
    echo "Not holiday";

您可以向网址添加参数以使其更具体。 https://developers.google.com/google-apps/calendar/v2/reference#Parameters

相关问题