Thanks am63 and Bim.

Unfortunately the problem is not in retrieving the event. I can successfully 
retrieve the event. My problem is when I try to save it.

I have managed to create a snippet of code that replicates my issue. The 
code is all here (as am63 was suggesting), the only dependence is on the 
Zend Gdata library.

As you will be able to see, the code:
_ performs some basic initializations
_ creates a secondary calendar
_ adds an event in that secondary calendar
_ retrieves the newly created event
_ updates it

All the steps but the last one work.


<?php

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_HttpClient');
Zend_Loader::loadClass('Zend_Gdata_Calendar');


// {{{ Settings: you just need to change these settings to run the whole 
script
$pathToKey = 
'/var/www/html/prod/example.com/www/config/google_data_rsakey.pem';
$sessionToken = '1/YbNh1kgsoYoZxP9hdW42QWvP4Qkd9lcN3UxMoYSQDPc';
// }}} End of Settings



// {{{ Init:
$client = new Zend_Gdata_HttpClient();
$client->setAuthSubPrivateKeyFile($pathToKey, null, true);          
$client->setAuthSubToken($sessionToken);
$gdataCal = new Zend_Gdata_Calendar($client, 
'google-calendar-example-integration');
$gdataCal->setMajorProtocolVersion(2);
$gdataCal->setMinorProtocolVersion(null);
/// }}} End of Init



// {{{ Creating new secondary calendar 'example'
$appCal = $gdataCal->newListEntry();
$appCal->title = $gdataCal->newTitle('example');
$ownCal = "http://www.google.com/calendar/feeds/default/owncalendars/full";;
$newCalendar = $gdataCal->insertEvent($appCal, $ownCal);

$calendarUrl = str_replace("%40", '@', $newCalendar->content->src);
// }}} End of Calendar creation



// {{{ Creating event
$event= $gdataCal->newEventEntry();
$event->title = $gdataCal->newTitle('New event from test');

$when = $gdataCal->newWhen();
$when->startTime = "2011-04-15";
$event->when = array($when);
$newEvent = $gdataCal->insertEvent($event, $calendarUrl);

// Event successfully created!
// }}} End of event creation


sleep(5);



// {{{ Retrieving newly created event
$newEventLongId = $newEvent->id->text;  // $newEventLongId: 
http://www.google.com/calendar/feeds/example.com_s9bn2jfsbm4aufob9mf5khfcpo%40group.calendar.google.com/events/g923kanho94cjo5tjk52b6g3pk
 
preg_match("!/([^/]+)$!", $newEventLongId, $matches);
$newEventId = str_replace('%40', '@', $matches[1]);  // $newEventId: 
g923kanho94cjo5tjk52b6g3pk

preg_match('![^/@]+@group\.calendar\.google\.com!', $calendarUrl, $matches); 
// $calendarUrl: 
https://www.google.com/calendar/feeds/[email protected]/private/full
$calendarId = $matches[0]; // $calendarId: 
[email protected]

$query = $gdataCal->newEventQuery();
$query->setUser($calendarId);
$query->setVisibility('private');
$query->setProjection('full');
$query->setEvent($newEventId);
$event = $gdataCal->getCalendarEventEntry($query);
// The event has been successfully retrieved
// }}} End of event retrieval



// {{{ Updating event
$event->title = $gdataCal->newTitle('New title');
$when = $gdataCal->newWhen();
$when->startTime = "2011-04-16";
$event->when = array($when);

// I have tried both of these approaches:
// $event->save();
// $gdataCal->insertEvent($event, $calendarUrl . '/' . $newEventId);

// They both give me this error:
// Expected response code 200, got 500 - Cannot access the calendar that you 
requested
// or this one:
// Expected response code 200, got 401 - Unknown authorization header
// }}} End of event updating


echo "All done";

-- 
You received this message because you are subscribed to the Google
Groups "Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/calendar/community/forum.html

Reply via email to