2012-05-03 42 views
0

我正在使用Zend框架與Google Calendar API一起使用IBM.com上的教程。我從教程中直接複製了一段代碼並試圖使用它,但似乎並沒有工作。我的PHP文件包括以下內容:使用Zend for Google日曆的PHP不生成網頁

<!--Some HTML is above here--> 
    <body> 
    <?php 
    // load library 
    require_once 'Zend/Loader.php'; 
    Zend_Loader::loadClass('Zend_Gdata'); 
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); 
    Zend_Loader::loadClass('Zend_Gdata_Calendar'); 
    Zend_Loader::loadClass('Zend_Http_Client'); 

    // create authenticated HTTP client for Calendar service 
    $gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; 
    $user = "[email protected]"; //replace with my username 
    $pass = "pass"; //replace with my password 
    $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal); 
    $gcal = new Zend_Gdata_Calendar($client); 

    // generate query to get event list 
    $query = $gcal->newEventQuery(); 
    $query->setUser('default'); 
    $query->setVisibility('private'); 
    $query->setProjection('basic'); 

    // get and parse calendar feed 
    // print output 
    try { 
     echo "<!--this comment is seen-->\n"; 
     $feed = $gcal->getCalendarEventFeed($query); 
     echo "<!--this comment is not seen-->\n"; 
    } catch (Zend_Gdata_App_Exception $e) { 
     //this doesn't happen. 
     echo "Error: " . $e->getResponse(); 
    } 
    ?> 
    <h1><?php echo $feed->title; ?></h1> 
    <?php echo $feed->totalResults; ?> event(s) found. 
    <p/> 
    <ol> 
    </body> 

從字面上看我這個代碼所做的唯一變化是用我自己的電子郵件地址和密碼,更換用戶名和密碼。當代碼執行到達try塊中的語句時,它似乎失敗,但不會捕獲到catch塊中,即使我將其更改爲捕獲任何異常,而不僅僅是Zend_Gdata_App_Exception。但生成的頁面源代碼清楚地顯示PHP正在崩潰:

<!--Some HTML is above here--> 
    <body> 
    <!--this comment is seen--> 

之後沒有任何東西。我在這裏學習PHP,所以任何幫助將非常感激!

+0

您發佈的大部分代碼與您的問題無關。 http://meta.stackexchange.com/a/129787/164367 – vascowhite

+0

@vascowhite對不起。我只是學習PHP,所以我不完全確定哪些代碼是相關的,哪些不是。不過,我縮小了一點。 – Daniel

+0

幹得好,謝謝。 :) – vascowhite

回答

1
<?php 

**$path = 'ZendGdata/library'; 
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $path);** 

require_once 'Zend/Loader.php'; 
Zend_Loader::loadClass('Zend_Gdata'); 
Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); 
Zend_Loader::loadClass('Zend_Gdata_Calendar'); 

... 

,並像他們在這裏解釋https://developers.google.com/google-apps/calendar/v1/developers_guide_php 這是谷歌官方日曆API開發人員指南,你應該下載ZendGdata /庫。您正在使用的代碼已被棄用。我仍在使用它,但他們建議你切換到谷歌日曆API v3,你可以在同一頁面找到相關文檔。