PHP 中同步更新和新增一筆資料至 Google Calendar,像是新增、更新和刪除,需要 Zend Gdata 函式庫,範例檔包含最新的 Zend Framework 版本。
// Code by Rchockxm
include_once("library/config.php");
// Update to Google Calendar.
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($googleAccount, $googlePassword, $service);
}
catch (Exception $e) {
echo "Could not connect to google calendar.";
}
$eventId = "";
$newTitle = "Silence Unlimited";
$newWhere = "Taiwan";
$newDescription = "Google Calendar API Test";
$eventOld = $gdataCal->getCalendarEventEntry($eventId);
if ($eventOld) {
$eventOld->title = $gdataCal->newTitle($newTitle);
$eventOld->where = array($gdataCal->newWhere($newWhere));
$eventOld->content = $gdataCal->newContent($newDescription);
try {
$eventOld->save();
} catch (Zend_Gdata_App_Exception $e) {
echo "Could not save to google calendar.";
}
}
需要注意的是必須儲存 $eventId,不然就無法對其更新和刪除。
部分代碼參考 Jerome Jaglale,特此感謝。
檔案下載: 圖一
- CRC32: A6C8FB77
- MD5: 31DA5894FFAFBEDA0C2FC4F52DFB2FFC
- SHA-1: B020FC95BD47E116C7078855FE2A68F3D89A0FB9
Silence Unlimited Download#1
Silence Unlimited Download#2