Google Calendar EventId问题(PHP Api)

时间:2010-10-09 05:00:11

标签: php google-calendar-api

我一直在使用谷歌日历的PHP api,并且已经非常沮丧。

我从google的页面下载了包含所有库的zend包,并且一直在处理提供的代码,以确保它符合我的要求。

我遇到的问题涉及从系统中恢复事件。提供的代码包括一个带有函数getEvent($ clientId,$ eventId)的演示,它基于文档和读取代码,我希望返回一个与我提供的Id匹配的日历中的事件。

所以在我的测试中,我创建了一个新事件,然后我尝试检索它。但是,每当我检索事件时,Zend_data_Gdata_App_HttpException都是:

function processPageLoad()
{
    global $_SESSION, $_GET;
    if (!isset($_SESSION['sessionToken']) && !isset($_GET['token'])) {
        requestUserLogin('Please login to your Google Account.');
    } else {
        $client = getAuthSubHttpClient();
        $id = createEvent ($client, 'Tennis with Beth',
         'Meet for a quick lesson', 'On the courts',
        '2010-10-20', '10:00',
        '2010-10-20', '11:00', '-08');
        $newEvent = getEvent($client, $id);
    }
}

createEvent()的代码是:

function createEvent ($client, $title = 'Tennis with Beth',
$desc='Meet for a quick lesson', $where = 'On the courts',
$startDate = '2008-01-20', $startTime = '10:00',
$endDate = '2008-01-20', $endTime = '11:00', $tzOffset = '-08')
{
    $gc = new Zend_Gdata_Calendar($client);
    $newEntry = $gc->newEventEntry();
    $newEntry->title = $gc->newTitle(trim($title));
    $newEntry->where  = array($gc->newWhere($where));

    $newEntry->content = $gc->newContent($desc);
    $newEntry->content->type = 'text';

    $when = $gc->newWhen();
    $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
    $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
    $newEntry->when = array($when);

    $createdEntry = $gc->insertEvent($newEntry);
    return $createdEntry->id->text;
}

最后getEvent()的代码是:

function getEvent($client, $eventId)
{
    $gdataCal = new Zend_Gdata_Calendar($client);
    $query = $gdataCal->newEventQuery();
    $query->setUser('default');
    $query->setVisibility('private');
    $query->setProjection('full');
    $query->setEvent($eventId);

    try {
        $eventEntry = $gdataCal->getCalendarEventEntry($query);
        return $eventEntry;
    } catch (Zend_Gdata_App_Exception $e) {
        var_dump($e);
        return null;

}

}

1 个答案:

答案 0 :(得分:0)

我们遇到同样的问题,只需分享我的解决方案。因为你分配$ id = createEvent() $ id将具有URL值。然后你使用$ id getEvent($ client,$ id);

解决方案是getCalendarEventEntry()可以有一个$查询或只有一个URL。

function getEvent($client, $eventId)
{
    $gdataCal = new Zend_Gdata_Calendar($client);

    try {
        $eventEntry = $gdataCal->getCalendarEventEntry($eventId);
        return $eventEntry;
    } catch (Zend_Gdata_App_Exception $e) {
        var_dump($e);
        return null;
}

希望它有所帮助!!

相关问题