使用PHP为Google日历事件设置提醒



我正在开发一个网站,使用这篇博客文章中的代码将事件添加到谷歌日历中。

现在,我想为每个活动设置一个提醒,该提醒设置在活动前15分钟。

有人能给我一些如何实现这一目标的指导吗?

在创建事件时设置提醒非常容易。您只需要在<gd:when></gd:when>标记中添加几行额外的行即可。

<gd:when startTime='2006-03-30T22:00:00.000Z' endTime='2006-03-30T23:00:00.000Z'>
  <gd:reminder minutes='15' method='email' />
  <gd:reminder minutes='15' method='alert' />
</gd:when>

这里有一个更新的addEvent()方法,包括对提醒的支持:

public function addEvent($params) {  
    $url = "http://www.google.com/calendar/feeds/{$this->getFeedEmail()}/private/full";  
    //startTime should be a time() value so we can convert it into the correct format  
    $params["startTime"] = date("c", $params["startTime"]);  
    //If no end-time is specified, set the end-time to 1 hour after the start-time  
    if(!array_key_exists("endTime", $params)) {  
        $params["endTime"] = date("c", strtotime($params["startTime"])+60*60*1);  
    }  
    $reminders = '';
    if(is_array($params['reminders'])) {
        foreach($params['reminders'] as $rem) {
            $reminders .= "<gd:reminder minutes='{$rem['minutes']}' method='{$rem['method']}' />"n; 
        }
    }
    $xml = "<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">  
              <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"></category>  
              <title type="text">{$params["title"]}</title> 
              <content type="text">{$params["content"]}</content> 
              <gd:transparency value="http://schemas.google.com/g/2005#event.opaque">  
              </gd:transparency>  
              <gd:eventstatus value="http://schemas.google.com/g/2005#event.confirmed">  
              </gd:eventstatus>  
              <gd:where valuestring="{$params["where"]}"></gd:where> 
              <gd:when starttime="{$params["startTime"]}" endtime="{$params["endTime"]}">
                {$reminders} 
              </gd:when> 
            </entry>";  
    //Do the initial POST to Google  
    $ret = $this->calPostRequest($url, $xml);  
    //If Google sends back a gsessionid, we need to make the request again  
    $matches = array();  
    if(preg_match('/gsessionid=(.*?)s+/', $ret, $matches)) {  
        $url .= "?gsessionid={$matches[1]}";  
        $ret = $this->calPostRequest($url, $xml);  
    }  
    //Parse the XML response (which contains the newly added entry)  
    $retFields = explode("n", $ret);  
    //print_r($retFields);  
    $entryXML = simplexml_load_string($retFields[count($retFields)-1]);  
    //Return an array containing the entry id (url) and the etag  
    return array(  
            "id"=> (string)$entryXML->id,  
            "etag"=> $this->getETagFromHeader($retFields),  
            "link"=> $this->getEditLinkFromHeader($retFields)  
            );  
}  

你可以这样称呼它:

$entryData = $cal->addEvent(array(  
    "title"=> "Auto Test event",  
    "content"=> "This is a test event",  
    "where"=> "Test location",  
    "startTime"=> time()+60*60*24*1,
    "reminders"=> array(
        array("method"=>"email", "minutes"=>"15"),
        array("method"=>"alert", "minutes"=>"15"),
    ) 
));  

相关内容

  • 没有找到相关文章

最新更新