作者appleboy46 (小恶魔)
看板PHP
标题[PHP] Zend 使用 Google Calendar API - 浏览事件
时间Fri Mar 27 13:04:13 2009
图文程式版:
http://blog.wu-boy.com/2009/03/27/1081/
昨天写了一篇 [PHP] Zend 使用 Google Calendar API - 环境建立架设,相信应该是非
常简单才对,那今天来介绍一下实做 Google Calendar API 的浏览、新增、删除、修改
事件的功能,在官方网站都有详细的 API 功能介绍,我只不过把功能整合完整一点,详
细请看 Google Calendar API With PHP。
1. 浏览功能:建立 index.php
/*
* include 昨天新增的config.inc.php 档案
*/
include('config.inc.php');
/*
* 提供Calendar 的服务名称
*/
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
/*
* 登入帐号密码
*/
$client = Zend_Gdata_ClientLogin::getHttpClient($googleAccount, $googlePassword, $service);
登入帐号密码部份,请开启 PHP 的 module:php_openssl.so,不然会出现底下错误讯息
:
Fatal error: Uncaught exception ‘Zend_Gdata_App_HttpException’ with message
‘Unable to Connect to ssl://www.google.com:443. Error
#46482968: Unable to
find the socket transport “ssl” - did you forget to enable it when you
configured PHP?’
解决方法就是修改 php.ini 档案,打开 extension=php_openssl.dll 这个 module 就可
以了,参考网站:[PHP] Unable to find the socket transport “ssl”,接下来在
config.inc.php 加入底下的 function
参数:
$client = 认证通过的变数
$startDate = 选择起始时间
$endDate = 选择结束时间
function outputCalendarByDateRange($client, $startDate='2009-01-01', $endDate='2009-12-31')
{
$gdataCal = new Zend_Gdata_Calendar($client);
$query = $gdataCal->newEventQuery();
$query->setUser('default');
$query->setVisibility('private');
$query->setProjection('full');
/*
* 可以指定 order by starttime or lastmodified
* starttime 起始时间
* lastmodified 最後修改
*/
$query->setOrderby('starttime');
$query->setStartMin($startDate);
$query->setStartMax($endDate);
$eventFeed = $gdataCal->getCalendarEventFeed($query);
foreach ($eventFeed as $event) {
echo "<h2><a href=\"event.php?id=".basename($event->id->text)."\">" . $event->title->text . "</a></h2>\n";
echo "<ul>\n";
echo "\t<li><b>内容:</b>".$event->content->text."</li>\n";
foreach ($event->where as $where) {
echo "\t<li><b>地点:</b>" . $where->valueString . "</li>\n";
}
foreach ($event->when as $when) {
echo "\t<li><b>起始时间: </b>" . $when->startTime . "</li>\n";
echo "\t<li><b>结束时间: </b>" . $when->endTime . "</li>\n";
}
echo "\t\t</ul>\n";
echo "\t</li>\n";
echo "</ul>\n";
}
}
这样我们就可以整个输出 index.php 档案了喔,那原始档案如下:
<?php
include('config.inc.php');
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // 提供Calendar 的服务名称
$client = Zend_Gdata_ClientLogin::getHttpClient($googleAccount, $googlePassword, $service);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>资策会 Appleboy 读取 Google 行事历</title>
</head>
<body>
<?php
outputCalendarByDateRange($client,'2009-01-01','2009-12-01');
?>
</body>
</html>
图文版:
http://blog.wu-boy.com/2009/03/27/1081/
--
Appleboy Blog:
http://blog.Wu-Boy.com 电脑技术、美食介绍、旅游资讯
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.87.162.162