1

Is there a way to get a single event using the Google Calendar .NET API or do I have to fetch all events and loop through them?

I would think there was a way using the "eid".

Sindre
  • 151
  • 1
  • 12

3 Answers3

2

You can retrieve a single event by adding the EventId to the query url, as in the following code:

CalendarService service = new CalendarService("test");
service.setUserCredentials(username, password);
EventQuery query = new EventQuery("https://www.google.com/calendar/feeds/default/private/full/s5uhaebith4jqn864j11ljkckg");
EventFeed feed = service.Query(query);

The returned EventFeed will only contain the single event whose eventId is "s5uhaebith4jqn864j11ljkckg".

Claudio Cherubino
  • 14,896
  • 1
  • 35
  • 42
  • This is not working for me. I always get an error `Execution of request failed: https://www.google.com/calendar/feeds/default/private/full/myeventid` Any idea? – seph Nov 18 '13 at 15:21
1

You should be able to use the GetEntry method on the service, passing in the URI associated with the event. I haven't personally used the .NET API to talk to Google Calendar though.

(Please note that although I work for Google, I post on my own behalf - don't take this as an "official Google post" :)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • I can not find a GetEntry function. There is a CalendarService.Get(string entryUri) function. But when I try that I get this error: "Invalid URI: The format of the URI could not be determined." – Sindre Jun 30 '11 at 10:26
  • @user685485: Could you post a link to exactly which version of the .NET API you're using? – Jon Skeet Jun 30 '11 at 10:28
  • I'm using the latest one from: http://code.google.com/p/google-gdata/downloads/list That's version 1.8. Here is a sample Uri that I'm using: https://www.google.com/calendar/event?eid=bGllZmRoZW5sYmptYTQ2bTJtZmt2MTFzbGsgMHFrMG02cXYwZGRuNDRjanI1YzdkYXJrMDRAZw – Sindre Jun 30 '11 at 10:29
  • @Sindre: Okay. I think GetEntry is in a newer version still under development. I would *expect* the CalendarService.Get method to work, or just building an EventQuery with that URL and giving it to the Query method. – Jon Skeet Jun 30 '11 at 10:49
  • @Jon Skeet `CalendarService service = new CalendarService("test"); service.setUserCredentials("test@gmail.com", "test"); CalendarQuery query = new CalendarQuery(activity.Url); CalendarFeed feed = service.Query(query);` This returns the following error: _Invalid URI: The format of the URI could not be determined._ I've tried looking around to see what others are doing, but I have not been able to find anyone updating a single event using this method. – Sindre Jun 30 '11 at 11:00
  • @Sindre: Build an EventQuery, not a CalendarQuery. What is `activity.Url` here? – Jon Skeet Jun 30 '11 at 11:01
  • @Jon Skeet: I get the exact same error using EventQuery and EventFeed. activity.Url is the url to the event: https://www.google.com/calendar/event?eid=aDljaWM5aTI5MzkxdmV0OW04azQ0OXFhc2sgbnRwd2Vic2hvcEBt – Sindre Jun 30 '11 at 11:08
  • @Jon Skeet: How would you go about updating or deleting a spesific calendar event? – Sindre Jun 30 '11 at 12:04
  • @Sindre: Not having used the API, and given that my expectations have already been confounded, I'd have to look into it separately to be honest. – Jon Skeet Jun 30 '11 at 12:05
0

you cannot pick an Event just by querying using above. The one shown above will work only for default calendars. If you have secondary calendars, the same query will work, but need to replace the emailId section in the feed URL to the Id of the secondary calendar you want to retrieve.

Ideally, if you just know the EventId and dont know under which list of calendars it belongs to, you have to do a search on all calendars you have, by replacing the calendarId in the above URL until you get your exact match.

This is how it works for me. If there are any other workaround, i request people to post replies please.

Thanks

AK0
  • 13
  • 5
  • It also won't work for exceptions to repeating events, apparently. http://stackoverflow.com/questions/8928163/trouble-fetching-google-calendar-event-exceptions-by-event-id-in-java I'd welcome anyone proving me wrong :-P – atraudes Jan 27 '12 at 02:53
  • Reg exceptions for repeating events, it works for us! If i query, i can get the exceptions as single events. To identify that, its EventId always has "_" underscore at some place. Usually, if its an exception, its eventid will be "_". Thats how we manage to read Exceptions for the repeating events. – AK0 Feb 07 '12 at 20:58