Google Calendar - get events from a SPECIFIC calendar
I'm hoping this will be relatively easy to someone who is familiar with the Google Calendar API, have done some searching but the API isn't giving me th开发者_运维知识库e answer!
Imagine that a Google Account has 3 calendars, all created by that user.
I'm trying to get events from a SPECIFIC calendar of that user, using the .NET Google API, as follows:
Calendar.userName = CalendarUserName;
Calendar.userPassword = CalendarPassword;
Calendar.feedUri = "https://www.google.com/calendar/feeds/default/private/full";
What that gives me is the feed of ALL events from ALL calendars, which is all very well, but then I need to parse them (presumably there is a way to identify but I don't know that either).
What would be ideal is for me to be able to cherry-pick and ask for a particular calendar, and only get the events from that one.
Is that possible? Is it only possible using the magic-cookie request?
Thanks Duncan
Have you read this one?
http://code.google.com/apis/calendar/data/2.0/reference.html#Event_feeds
And this one?
http://code.google.com/apis/calendar/data/2.0/developers_guide_dotnet.html#RetrievingEvents
This is the key part to understand it I think:
Note: Some of these code snippets show adding an event to a default calendar or to a specific user's primary calendar (substituting a gmail address for the 'default' string in the POST URI), but events can also be added to non-primary calendars as well. To do this, you simply need the calendar ID which can be retrieved from the allcalendars feed, and is also shown in the Calendar Settings page of the UI. This id is again used in the feed URI: https://www.google.com/calendar/feeds/id/private/full.
http://code.google.com/apis/calendar/data/2.0/developers_guide_dotnet.html#RetrievingCalendars
Dim singleUseToken As String = Request.getString("token")
Session("sessionToken") = AuthSubUtil.exchangeForSessionToken(singleUseToken, Nothing)
Dim authFactory As GAuthSubRequestFactory = New GAuthSubRequestFactory("cl", "LeaveCalendar")
authFactory.Token = Session("sessionToken").ToString
Dim service As Service = New Service("cl", authFactory.ApplicationName)
service.RequestFactory = authFactory
Dim query As New CalendarQuery()
query.Uri = New Uri("https://www.google.com/calendar/feeds/default/owncalendars/full")
Dim resultFeed As AtomFeed = CType(service.Query(query), AtomFeed)
For Each entry As AtomEntry In resultFeed.Entries
Response.Write("Your calendar:" & entry.Title.Text)
Response.Write("<br>")
Response.Write("<br>Calendar id " & entry.SelfUri.ToString.Substring(64))
Next
I tried that link but always receive Error, exception about Atom stuff. I changed that code a litte bit, especially these 2 lines:
1) Dim resultFeed As AtomFeed = CType(service.Query(query), AtomFeed)
2) For Each entry As AtomEntry In resultFeed.Entries
I hope it helps other VB.NET users
精彩评论