We're speaking at
CFUnited 2008:
CFUnited - The Premiere ColdFusion Technical Conference

Search

Calendar

SunMonTueWedThuFriSat
    123
45678910
11121314151617
18192021222324
25262728293031

Subscribe Enter your email address to subscribe to this blog. You'll receive an email when we write a new post.

Recent Entries Come On In, Rails-The Water's Warm
Shan's Simple Examples: File uploads with Flex and ColdFusion

Recent Comments Google Calendar API - Creating a new Calendar with ColdFusion
Steve Julian said: When and where are you going to post the finished CFC's ? Thanks [more]

Three Phases of Programmer Development
Pat Branley said: I normally think of those phase 2 people as 'programmers' and the phase 3 people as 'developers'. I... [more]

New Job Title: Front End Engineer
Sean Corfield said: Well, there's always the excellent Fusion Authority Quarterly Journal... [more]

Down To The Wire: HTTP Sniffers
Brian M said: I second the mention of the Charles Web Debugging Proxy that Tariq mentioned. It is fantastic. It s... [more]

New Job Title: Front End Engineer
Patrick said: Heya Sean. Good point. I never understood how they did things over there at SysCon, and I understand... [more]

Archives By Subject Business of Software (4) [RSS]
ColdFusion (318) [RSS]
Conferences (6) [RSS]
Databases (87) [RSS]
Flex & Flash (109) [RSS]
Fusebox (87) [RSS]
General Development (29) [RSS]
Google (9) [RSS]
Hardware (5) [RSS]
JVM & Java (132) [RSS]
Linux (20) [RSS]
Miscellaneous (254) [RSS]
Performance (8) [RSS]
SeeFusion (36) [RSS]
Shan's Simple Examples (6) [RSS]
User Interface (3) [RSS]
Windows (5) [RSS]

Archives By Poster Daryl Banttari (10)
Nat Papovich (29)
Patrick Quinn (36)
Shannon Hicks (22)
Steve Nelson (21)
Tyson Vanek (3)


bottom corner

Google Calendar API: Using ColdFusion to get a list of Calendars

Before we handle the methods for editing a calendar, we need to make sure we're editing the correct calendar. To do that we need to get a list of the calendars from Google. This method we'll look at today is very simple. So, let's jump right into the code.

<cffunction name="getCalendars" >
      <cfargument name="subSessionToken" type="string" required="Yes">
      <cfargument name="gsessionid" type="string" required="Yes">
      <cfargument name="includeAllCalendars" type="boolean" default="true">
      <cfset var local=structnew()>
      <cfif arguments.includeAllCalendars>
         <cfset local.whichCalendars="allcalendars">
      <cfelse>
         <cfset local.whichCalendars="owncalendars">
      </cfif>
      <cfhttp url="http://www.google.com/calendar/feeds/default/#local.whichCalendars#/full?gsessionid=#arguments.gsessionid#" method="get" redirect=false>
         <cfhttpparam type="HEADER" name="Authorization" value="AuthSub token=#arguments.subSessionToken#">
      </cfhttp>
      
      <cfxml variable="local.getCalendars"><cfoutput>#cfhttp.filecontent#</cfoutput></cfxml>
      
      <cfreturn local.getCalendars/>
   </cffunction>

We start with our usual two login arguments of a "subSessionToken" and "gSessionId". These tokens tell Google whos calendars to get. I added a third token to this method called "includeAllCalendars". This argument is a boolean true or false value. If it is set to false it will only include calendars that are 'owned' by the user. Whereas true will show all calendars the user has access to. So for example, if a coworker shares her calendar with you, you won't 'own' that calendar, but you'll have access to it.

The next section is a simple cfhttp GET. The final section is just parsing the XML that Google returns. That's it, we're done.

I'll do another post to examine the data that Google returns, it's important to understand it. I'll be back shortly I need to run to the chiropractor. Get it? back... oh forget it.

-Steve Nelson

Comments
Steve, I used the google calendar API recently and ran into a problem where it would only return 20-25 events max. No matter what parameters I passed it, I could not get the complete list. Have you run into that? I was just wondering if that was fixed yet. Thanks.
# Posted By Steve House | 2/1/08 5:37 PM
You need to set the value of "max-results" to a large number. By default they set it to 25 so you don't accidentally get an enormous packet.

I'll post a bunch about events next week. I'm taking this slow because there is a LOT going on with the Google Calendar API.
# Posted By Steve Nelson | 2/2/08 11:05 AM
Just a minor code suggestion,when you set the variable local.whichCalendars, you don't need the else. Before you do the if, set it to "owncalendars" and have the if just be the first part. A bit let code and it does the same thing. In fact, and I know it may seem trite, I would argue it's a bit more clear that local.whichCalendars will always be "owncalendars" unless that condition is met. but that's just my two-bits worth....
# Posted By Allen | 2/13/08 9:33 PM
Fair enough. If that's a pet peeve of yours I'll change it.
# Posted By Steve Nelson | 2/15/08 6:20 PM

bottom corner