PHP Google日历从特定日历获取事件

时间:2012-11-05 17:16:49

标签: php google-calendar-api

我在Google日历中有2个或更多日历。 我可以将事件添加到特定日历中,例如:

[...]
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$service = new Zend_Gdata_Calendar($client);

//Set up  that loop again to find the new calendar:
$calFeed = $service->getCalendarListFeed();
foreach ($calFeed as $calendar) {
    if($calendar->title->text == "Calendar2")
         $appCalUrl = $calendar->content->src;
    }
}
[...]

try {

    $event           = $service->newEventEntry();
    $event->title    = $service->newTitle($title);

    $when            = $service->newWhen();
    $when->startTime = $start;
    $when->endTime   = $end;

    $event->when     = array($when);
    $newEvent        = $service->insertEvent($event, $appCalUrl);

    // fetch URI for edit, delete
    $uri = $newEvent->id->text;

} catch (Zend_Gdata_App_Exception $e) {
    echo "Error: " . $e->getResponse();
}

$ uri会产生如下字符串: http://www.google.com/calendar/feeds/7b06drcai3lhc4lhhb0lgvv7sk%40group.calendar.google.com/private/full/ndp7g62tbbvknhi8bbhh9jfu9o

然后,使用:

try {

     $title = "test2";
     $event = $service->getCalendarEventEntry($uri);
     $event->title = $service->newTitle($title);
    } catch (Zend_Gdata_App_Exception $e) {
    die("Error: " . $e->getResponse());
} 

这总会导致如下错误:BAD /无效URI

我一直在搜索,在多个例子中都说URI格式应该是这样的:

getCalendarEventEntry('http://www.google.com/calendar/feeds/default/private/full/' . $id);

只获取ID也不起作用。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

找到答案:

字符串的格式为:

http://www.google.com/calendar/feeds/$calendar_id%40group.calendar.google.com/private/full/$event_id