昨天寫了一篇
[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?’ in C:\AppServ\www\Zend\library\Zend\Gdata\ClientLogin.php:140 Stack trace: #0 C:\AppServ\www\Zend\GClab\index.php(5): Zend_Gdata_ClientLogin::getHttpClient(‘xxxxx@gma…’, ”, ‘cl’) #1
解決方法就是修改 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 "\n";
echo "
\n";
echo "\t- 內容:".$event->content->text."
\n";
foreach ($event->where as $where) {
echo "\t- 地點:" . $where->valueString . "
\n";
}
foreach ($event->when as $when) {
echo "\t- 起始時間: " . $when->startTime . "
\n";
echo "\t- 結束時間: " . $when->endTime . "
\n";
}
echo "\t\t
\n";
echo "\t\n";
echo "\n";
}
}
這樣我們就可以整個輸出 index.php 檔案了喔,那原始檔案如下:
資策會 Appleboy 讀取 Google 行事曆
上一篇:
[PHP] Zend 使用 Google Calendar API – 環境建立架設
下一篇:
[PHP] Zend 使用 Google Calendar API – 編輯事件
Related
Pingback: [PHP] Zend 使用 Google Calendar API - 環境建立架設 | 小惡魔 - 電腦技術 - 生活日記 - 美食介紹 - AppleBOY()
Pingback: [PHP] Zend 使用 Google Calendar API - 編輯事件 | 小惡魔 - 電腦技術 - 生活日記 - 美食介紹 - AppleBOY()
Pingback: 網站製作學習誌 » [Web] 連結分享()