【问题标题】:Google Calendar EventId issues (PHP Api)Google 日历 EventId 问题(PHP Api)
【发布时间】:2011-04-23 04:26:49
【问题描述】:

我一直在使用谷歌日历的 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;

}

}

【问题讨论】:

    标签: php google-calendar-api


    【解决方案1】:

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

    解决方案是 getCalendarEventEntry() 可以有一个 $query 或只是一个 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;
    }
    

    希望对你有帮助!!

    【讨论】:

    • 我最近从另一个网站上看到了这个,但它完全正确,所以我把它交给你了。感谢您的回复。
    猜你喜欢
    • 1970-01-01
    • 2018-06-12
    • 2022-01-18
    • 2018-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多