Jump to content

Update google Calendar events using gData?


jarv

Recommended Posts

Hi,

 

at the moment, I am pulling events from my Google Calendar and showing them by calling the outputCalendarByDateRange() function below. Now would like to be able to update/Delete them

 

<html>
<head>
<title>Gdata</title>
</head>
<body>
<?php
//session_start();
//ini_set('display_errors',1);
//ini_set('display_startup_errors',1);
//error_reporting (E_ALL);
//DATES
if(!isset($_REQUEST['from'])){
$newdateTimeStart = "01/01/2009";
} else {
$newdateTimeStart = $_REQUEST['from'];
}
if(!isset($_REQUEST['to'])){
$newdateTimeEnd = "11/05/2011";
} else {
$newdateTimeEnd = $_REQUEST['to'];
}
$startyear = substr($newdateTimeStart, 6, 4);
$startmonth = substr($newdateTimeStart, 3, 2);
$startday = substr($newdateTimeStart, 0, 2);
$newdateTimeStart = $startyear.'-'.$startmonth.'-'.$startday;

$endyear = substr($newdateTimeEnd, 6, 4);
$endmonth = substr($newdateTimeEnd, 3, 2);
$endday = substr($newdateTimeEnd, 0, 2);
$newdateTimeEnd = $endyear.'-'.$endmonth.'-'.$endday;

$dateStart = $newdateTimeStart;
$dateEnd = $newdateTimeEnd;


//between dates
function outputCalendarByDateRange($client, $startDate='2007-05-01', 
                                   $endDate='2007-08-01') 
{
  $gdataCal = new Zend_Gdata_Calendar($client);
  $query = $gdataCal->newEventQuery();
  $query->setUser('default');
  $query->setVisibility('private');
  $query->setProjection('full');
  $query->setOrderby('starttime');
  $query->setStartMin($startDate);
  $query->setStartMax($endDate);
  $eventFeed = $gdataCal->getCalendarEventFeed($query);
  echo "<ul>\n";
  foreach ($eventFeed as $event) {
    echo "\t<li>" . $event->title->text .  " (" . $event->id->text . ")\n";
    echo "\t\t<ul>\n";
    foreach ($event->when as $when) {
      echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n";
    }
    echo "\t\t</ul>\n";
    echo "\t</li>\n";
  }
  echo "</ul>\n";
}

//Connect to google calendar
    //If you do not have access to the PHP.INI file on the remote server, you should use the following statement to set the path information for Zend framework
    $clientLibraryPath = 'libraries';
    $oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);
    // load ZEND classes
    require_once 'Zend/Loader.php';
    Zend_Loader::loadClass('Zend_Gdata');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
    Zend_Loader::loadClass('Zend_Gdata_Calendar');
    Zend_Loader::loadClass('Zend_Http_Client');
    // connect to calendar service
    $gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
    $user = "***"gmail.com"; //Insert your google username
    $pass = "***"; //Insert your Google password
    //$user = stripslashes($_POST['user']); //Insert your google username
    //$pass = stripslashes($_POST['pass']); //Insert your Google password
    $_SESSION['user'] = $user;
    $_SESSION['pass'] = $pass; 
    $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
    $gcal = new Zend_Gdata_Calendar($client);



function createEvent ($client, Zend_GData_Calendar $gcal, $title = 'testing google calendar',
    $desc='this is great', $where = 'at work',
    $startDate = '2011-04-20', $startTime = '10:00',
    $endDate = '2011-04-20', $endTime = '11:00', $tzOffset = '+01')  
    {
      $newEvent = $gcal->newEventEntry();
      
      $newEvent->title = $gcal->newTitle($title);
      $newEvent->where = array($gcal->newWhere($where));
      $newEvent->content = $gcal->newContent("$desc");
      
      $when = $gcal->newWhen();
      $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
      $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
      $newEvent->when = array($when);
    
      // Upload the event to the calendar server
      // A copy of the event as it is recorded on the server is returned
      $createdEvent = $gcal->insertEvent($newEvent);
      return $createdEvent->id->text;
    }

echo outputCalendarByDateRange($client, "$dateStart", "$dateEnd");

?>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.