开发者

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

开发者 https://www.devze.com 2022-12-18 02:43 出处:网络
I\'m trying to add an event to a specific calendar in google calendar and I just 开发者_如何学JAVAdon\'t find how. Here\'s my code :

I'm trying to add an event to a specific calendar in google calendar and I just 开发者_如何学JAVAdon'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.


Your code is working with the default Google Calendar for your specified user name and password. (IE it is using the default calendar for username@gmail.com) 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号