views:

912

answers:

2

Hey everyone,

I have modified my PHP web app to add events to a Google Calendar. Currently, it adds successfully.

However, now I wish to delete and edit events. This seems easy to do, except for the fact that I don't know what event URL is associated with each event.

Am I supposed to set this event URL (or ID?) upon adding an event? How am I supposed to figure out what it is?

I can't seem to find this information anywhere else...

Thanks!

EDIT:

I have been using the Zend Framework for this (Gdata package)...

EDIT:

$newIncludePath = array();

$newIncludePath[] = '../ZendGdata-1.8.4PL1/library';

$newIncludePath = implode($newIncludePath);

set_include_path($newIncludePath);



  // load 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 service

  $gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;

  $user = "********@gmail.com";

  $pass = "*****";

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

  $gcal = new Zend_Gdata_Calendar($client);



  // construct event object

  // save to server      

  try {

    $event = $gcal->newEventEntry();        

    $event->title = $gcal->newTitle($title); 

    $event->content = $gcal->newContent($desc);       

    $when = $gcal->newWhen();

    $when->startTime = $date;

    $when->endTime = $date;

    $event->when = array($when);        

    $gcal->insertEvent($event);   

echo $event->getEditLink()->href;


  } catch (Zend_Gdata_App_Exception $e) {

    echo "Error: Unable to add event to Google Calendar" . $e->getResponse();

  }
+1  A: 

You could have a look at Zend_Gdata and Zend_Gdata_Calendar : those would probably help for all the hard work -- and if you don't have to spend code to communicate with Google's API, it gives you more time to develop other things ;-)

And it seems it can be used outsid of the Zend FRamework : it's even available as a standalone download : http://framework.zend.com/download/gdata

(If you really want to do it yourself, you can still try to understand how Zend_Gdata does it ^^ )

Pascal MARTIN
Sorry, I should have mentioned that I have been using the Zend Framework to achieve what I have so far. But, even looking into the API, I can't seem to find out how to get an event url for a particular event!
behrk2
+1  A: 

This is plainly documented in the Zend_Gdata documentation:

http://framework.zend.com/manual/en/zend.gdata.calendar.html#zend.gdata.calendar.deleting_events

// Option 1: Events can be deleted directly
$event->delete();

or

// Option 2: Events can be deleted supplying the edit URL of the event
// to the calendar service, if known
$service->delete($event->getEditLink()->href);

It sounds like you need the latter.

Edit:

Get the edit link from your $event. It's shown in the code above:

$event->getEditLink()->href;

This will be available on a saved event. e.g.

$newEvent = $service->insertEvent($event);
echo $newEvent->getEditLink()->href;
hobodave
hobodave - I looked at that, but what is confusing me is the "supplying the edit URL of the even" part. Let's say I just added an event, and now I want to delete it. How do I know what that event URL is? I added an edit to my original post with how I am adding an event, in case it helps any. Thanks for your help on this.
behrk2
This was in my initial answer. I updated to make it clearer. Please *try* the code shown.
hobodave
Thanks for your help.
behrk2
hobodave-When I do the following:echo $event->getEditLink()->href;(Which is done right after an insert), nothing is echo'd. There output is just blank...Any ideas? I don't know why this has been so hard for me!
behrk2
I figured it out, I was missing: "$newEvent->when = array($when);"
behrk2