Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an Event to a "specific" Google Calender with GData API

I'm trying to add an event to a specific calendar in google calendar and I just don't find how. Here's my code :

        CalendarService service = new CalendarService("MyTEst");
        service.setUserCredentials("Username", "Password");
        EventEntry entry = new EventEntry();

        // Set the title and content of the entry.
        entry.Title.Text = "title";
        entry.Content.Content = "test";

        // Set a location for the event.
        Where eventLocation = new Where();
        eventLocation.ValueString = "Location";
        entry.Locations.Add(eventLocation);

        When eventTime = new When(DateTime.now, DateTime.now.AddDays(2));
        entry.Times.Add(eventTime);

        Uri postUri = new Uri("http://www.google.com/calendar/feeds/default/private/full");

        // Send the request and receive the response
        AtomEntry insertedEntry = service.Insert(postUri, entry);

Can anyone help me out with this one?

Edit

Maybe I should mention that this fonctionnability is only accessible for an administrator of a site which want to easly add rendez-vous and note to his google calendar so I automaticaly authenticated it with "hardcoded" value so I'm sure the username and password are ok.

like image 820
Simon Dugré Avatar asked Jan 27 '10 21:01

Simon Dugré


1 Answers

Your code is working with the default Google Calendar for your specified user name and password. (IE it is using the default calendar for [email protected]) You can see this because the URI points to "/feed/default/private". If you want to post the event to another calendar the user name must authorized to post to that calendar, and you need to post to THAT calendars private uri.

EDIT: The default format of this private URL is "http://www.google.com/calendar/feeds/CALENDAR_ID/private/full"

To find the calendar id, it is next Calendar Address in the calendar settings page on Google Calendars. It will appear similar to this:

"***************************@group.calendar.google.com"

The final URL would be:

EDIT: "http://www.google.com/calendar/feeds/***************************@group.calendar.google.com/private/full"

This will go in your Uri postUri = new Uri();

EDIT:

My mistake was that I mentioned that you need to also include the private key after the word private. You do not actually have to do this. I have verified that I could successfully post to a secondary calendar by removing the private key.

like image 111
Dan Joseph Avatar answered Sep 23 '22 01:09

Dan Joseph