我正在关注http://www.ibm.com/developerworks/library/x-googleclndr/上有关使用Google Calendar API的教程,但我遇到了一些奇怪的问题。我的PHP代码看起来像这样
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 = "daniel.lieberman610@gmail.com";
$pass = "*******";
$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($user);
$query->setVisibility('private');
$query->setProjection('basic');
//get and parse calendar feed
//print output
try {
$feed = $gcal->getCalendarEventFeed($query);
echo "<!--comment-->\n";
} catch (Exception $e) {
echo "<!--different comment-->\n";
}
try块内部发生了某种异常,但Zend_Gdata_App_Exception
未发生异常,因为未显示错误消息。我无法弄清楚我做错了什么。
另外,我在这里学习PHP。非常感谢你的帮助。
答案 0 :(得分:0)
将try代码移动到文件的开头。是否显示错误?在这里,您将找到一个我在Joomla扩展https://github.com/Digital-Peak/GCalendar/blob/master/com_gcalendar/admin/libraries/GCalendar/GCalendarZendHelper.php
中使用的工作示例顺便提一下,我建议转移到新的谷歌日历API v3,因为他们可能会在明年关闭版本2(使用Zend)。这是libs https://developers.google.com/google-apps/calendar/downloads
的链接