Question

I'm trying to insert a new event into Google Calendar, which I can do fine by the following:

$sname = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar
$client = Zend_Gdata_ClientLogin::getHttpClient($userName,$password,$sname);
$service = new Zend_Gdata_Calendar($client);

$event = $service->newEventEntry();
$event->title = $service->newTitle($name);
$event->when = array($when);
$newEvent = $service->insertEvent($event);

However, this will only insert into the default calendar. I am trying to use the URI argument of insertEvent to get where I need to go:

$uri = "http://www.google.com/calendar/feeds/default/something@somethingelse.com/private/full";
$newEvent = $service->insertEvent($event, $uri);

This hasn't worked. I've tried encoding and decoding the URI, which gives me different error messages, but I just can't get this to work. I've been Googling solutions for hours now with no luck. Can anyone help?

Thanks. - Dave

Was it helpful?

Solution

Found the issue: The URI above doesn't work: "http://www.google.com/calendar/feeds/default/something@somethingelse.com/private/full";

should not have the default section there.

Also, the @ sign should be replaced by encoding. So it should be: "http://www.google.com/calendar/feeds/something%40somethingelse.com/private/full";

OTHER TIPS

I have been fighting this for awhile and I finally got it to work. This is not wrapped nicely, but this is the answer I was looking for

First you have to get the calendar ID. If you go into your calendar and click on the down arrow icon next to the name you will see an option for Calendar Settings. Select that menu item. Near the bottom you will see Calendar Address. It will take a moment to find the Calendar ID and it will look something like this

(Calendar ID: o4g3921hdiaq5p8kdat2l4vgis@group.calendar.google.com)

You want o4g39j1hdihq4p8kdat2l4vgis@group.calendar.google.com

Down the road I will want to get this in php but for now I can hard code. So I set a variable to this

$calendar_user = 'o4g39j1hdihq4p8kdat2l4vgis@group.calendar.google.com';

When retrieving events you will setUser like this

$gdataCal = new Zend_Gdata_Calendar($client);
$query = $gdataCal->newEventQuery();
$query->setUser($calendar_user);

But when you are adding event you can't do that you have to use the $calendar_user at the point where you insert the event.

So here is the complete code

$calendar_user = 'o4g39j1hdihq4p8kdat2l4vgis@group.calendar.google.com';
$user = 'myemail@yahoo.com';
$pass = 'mygooglecalendarpassword';
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar
$client = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,$service);

$gc = new Zend_Gdata_Calendar($client);
$newEntry = $gc->newEventEntry();
$newEntry->title = $gc->newTitle("mytitle");
$newEntry->where  = array($gc->newWhere("meeting place"));

$newEntry->content = $gc->newContent("Meeting description");
$newEntry->content->type = 'text';

$when = $gc->newWhen();
$when->startTime = "{'2012-06-28'}T{'10:00'}:00.000{'-08'}:00";
$when->endTime = "{'2012-06-28'}T{'11:00'}:00.000{'-08'}:00";
$newEntry->when = array($when);

$createdEvent = $gc->insertEvent($newEntry, "http://www.google.com/calendar/feeds/".$calendar_user."/private/full");

Now I hope that is helpful. I tell you it took me way too long to figure this out, but I am not the smartest guy in the world.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top