使用Google Calendar API通过短信通知添加活动

时间:2011-03-15 08:12:11

标签: php zend-framework google-calendar-api

我正在尝试使用短信通知向我的日历添加一个事件。我成功添加了一个事件,但我无法向其添加通知。

以下是我当前的代码:http://en.paidpaste.com/8Lnv4w

有关Google Calendar API的更多信息:

Data API Developer's Guide: PHP

Integrate your PHP application with Google Calendar

更新

似乎API被破坏或类似的东西,尝试了一切......

1 个答案:

答案 0 :(得分:1)

正确的代码:

<?php
$path = 'GData';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');

$user = '*';
$pass = '*';
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar

$client = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,$service);

////////////// Add event

function createEvent ($client, $title = 'Tennis with Beth',
$desc='Meet for a quick lesson', $where = 'On the courts',
$startDate = '2011-03-14', $startTime = '21:30',
$endDate = '2011-03-14', $endTime = '22:00', $tzOffset = '+01')
{
    $gdataCal = new Zend_Gdata_Calendar($client);
    $newEvent = $gdataCal->newEventEntry();

    $newEvent->title = $gdataCal->newTitle($title);
    $newEvent->where = array($gdataCal->newWhere($where));
    $newEvent->content = $gdataCal->newContent("$desc");
    $when = $gdataCal->newWhen();
    $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
    $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
    // PÅMINNELSE!
    $reminder = $gdataCal->newReminder();
    $reminder->method = "sms";
    $reminder->minutes = "1";
    // LÄGG TILL I WHEN
    $when->reminders = array($reminder);
    // LÄGG TILL WHEN
    $newEvent->when = array($when);

    $createdEvent = $gdataCal->insertEvent($newEvent);
    return $createdEvent->id;
}

$eventId = createEvent($client, 'PartyPart', 'Kim Il Jong och jag', 'Mitt hus', '2011-03-15', '22:00', '2011-03-15', '22:05', '+01' );
?>