[教學] 使用 Google Calendar API - 瀏覽事件

看板PHP作者 (小惡魔)時間16年前 (2009/03/27 13:04), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
圖文程式版: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
文章代碼(AID): #19p5vFjT (PHP)
文章代碼(AID): #19p5vFjT (PHP)