1 Replies - 2700 Views - Last Post: 17 June 2013 - 02:09 PM Rate Topic: -----

#1 squibby   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 91
  • Joined: 21-January 12

How to retrieve last inserted event from Google Calendar API

Posted 17 June 2013 - 01:39 PM

Hi i have been playing with the fantastic Google calendar API along with Zend Gdata class for adding/retrieving events etc. Is there any way to retrieve the last inserted event from the calendar (not the most recent by date but by actual entry).

Basically im looking for the same functionality as mysql_insert_id php function but for google calendar. So i can update my local events table with a unique event ID which can be used for deleting/editing events elsewhere in my application.

//get all event data from a form, sanitise and then insert to  my event table (omitted)

     // 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 = "xxxx";
      $pass = "xxxx";
      $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
      $gcal = new Zend_Gdata_Calendar($client);
      
	  
	  //Set variables so zend can accept
	  $startDate = $startDate.'T'.$startTime;
	  $endDate = $endDate.'T'.$endTime;
	  
	  
	  //Hide title for private events	  
	  if ($privacy == 'YES'){
		$title = 'PRIVATE EVENT '.mysql_insert_id();
	  }
	
      // construct event object
      // save to server      
      try {
        $event = $gcal->newEventEntry();        
        $event->title = $gcal->newTitle($title);        
        $when = $gcal->newWhen();
        $when->startTime = $startDate;
        $when->endTime = $endDate;
        $event->when = array($when); 
		
        $gcal->insertEvent($event);   
      } catch (Zend_Gdata_App_Exception $e) {
        echo "Error: " . $e->getResponse();
      }
      echo 'Event successfully added!';      

//now i need to get last inserted event id from google calendar and update my own event table



This post has been edited by squibby: 17 June 2013 - 01:42 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How to retrieve last inserted event from Google Calendar API

#2 squibby   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 91
  • Joined: 21-January 12

Re: How to retrieve last inserted event from Google Calendar API

Posted 17 June 2013 - 02:09 PM

ok this was obvious and i missed it. After inserting to the calendar you can call something like this to retrieve the id.

$eventUri = $newEvent->id->text;


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1