GoogleDocs CFC

This post is more than 2 years old.

Many, many moons ago I released some code to work with Google's Documents service. It supported listing documents and downloading... kinda. At the time, downloading wasn't officially documented, and the code completely failed for hosted accounts. Well, Google finally officially released download support, so I spent some time today updating the CFC. With the CFC you can now:

  • Download all documents
  • Download a type of document (documents versus presentations versus spreadsheets)
  • Download starred documents
  • Search the text inside the documents
  • Download a document in any format Google supports. This is rather cool actually. You can download a PNG of a document and you get a thumbnail. You can export a presentation into SWF format. You get the idea.

I do not currently support folder operations or any document uploading. I figured that people would use this CFC to embed Google edited items within their own web site. It is a great way to give clients a nice editor while still displaying their content on their web site.

The download is below. Ok, so now I need to put on my cranky pants for a minute. While working with the API I ran into a few issues. An engineer from Google really helped me out on their forums, and I appreciate that, but as my readers know, I'm kinda snobbish about my APIs (can you be an API snob) so I thought I'd share some feedback. Who knows - maybe I'll get a job offer from the big G. Anyway, in no particular order, here is what caused me to yank a few hairs out today.

  1. When it comes to exporting, Google offers a variety of formats. You can't use all the same formats for all the same document types, which is fine, I mean, I don't see how or why you would want a SWF export of a written document. However, for spreadsheets, instead of supplying a format like XLS or SWF, like you do for presentations and documents, you provide a number. You have to look up CSV, for example, and supply a number. Silly. My CFC simply wraps their numbers with a utility function.

  2. Speaking of document types - all 3 use a different url for downloading. So that's one url to get your list, and 3 different ones for downloading. Eh? Would I be crazy to expect just one url with different actions?

  3. For spreadsheets, if you get a text format, you must specify a sheet number. And it's 0 indexed. Ok, I know some people think 0 based arrays make sense. But you will never convince me that it makes sense to use 0-based indexing outside of arrays. Again, my CFC simply 'fixes' this for yo.

  4. Before you do anything with Google, you perform an authentication request. But for some reason, the authentication request that lets you list docs and lets you download doesn't work downloading spreadsheets. You have to perform a second authentication request just to download a spreadsheet. -boggle- I got around this ok in the code (pretty nicely I think) but still, this is something Google should fix. (And they know about it so most likely the will.)

  5. Oh, here is a good one. You need a document id to download a document. Ok, that's sensible enough. But the XML returned from the document list doesn't give you the ID "clean." You have to parse a string by splitting on %3A. Isn't XML supposed to make this simpler? (Again, Google knows about this and will eventually fix it.)

Anyway, enough ranting. I hope this helps folks. This isn't up on RIAForge yet. I'm considering consolidating my various Google projects into one uber Google codebase like my Yahoo stuff.

Download attached file.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Phillip Senn posted on 2/20/2009 at 7:27 PM

I'm very excited to see this post!
I had a bit of confusion over line 4 of test2public.cfm because you were using a bit of lingo when you said "email addy".
Email addy? Who is addy? Could that mean EmailDaddy without the D?
Oh! Address! He means MyUsername@gmail.com!

Comment 2 by Raymond Camden posted on 2/20/2009 at 7:35 PM

"Docs? We don't need no stinkin' docs!"

Comment 3 by Scott Wimmer posted on 2/20/2009 at 9:24 PM

I too am excited. This "closes the loop" for my web-based online data submission project from customers. If it will download the spreadsheet as an xls I will be able to transfer it into MS Access for processing.

BUT (of course)

When I change the format argument (line 42 of test2public) from 'html' to 'xls' I get error:

ByteArray objects cannot be converted to strings.

The error occurred in C:\Websites\73172bkj\SwatchDog\Helpdesk\test2public.cfm: line 46
44 : <cfoutput>
45 : <pre>
46 : #content#
47 : </pre>
48 : </cfoutput>

Any clues?

Comment 4 by Raymond Camden posted on 2/20/2009 at 9:26 PM

XLS is a binary format. You can't output it to screen. Save it to the file system and then you can open it with Excel, OpenOffice, Numbers.

Comment 5 by Scott Wimmer posted on 2/20/2009 at 9:45 PM

Ray:
It worked by replacing #content# (line 47 or so in test2public.cfm) with <cfset fileWrite(expandPath("./BC.xls"), content)>

Thank you very much. A very large deal for me...

Phil said he sent you a tie fighter once.
I am in a gifting mood. What would you like?

Yours truly grateful,
SW

Comment 6 by Raymond Camden posted on 2/20/2009 at 9:47 PM

Well, I'd love to say that your gratitude is enough, but, nah, I'm a greedy jerk. ;)

If you visit my wishlist, any video game related item would be fine, especially the MS Points though. (Going to use that for the new Galatrix game coming out and the Fallout3 expansion.)

Comment 7 by Scott Wimmer posted on 2/20/2009 at 10:02 PM

4000 points should arrive Feb 25 from amazon.

Enjoy!

Comment 8 by Raymond Camden posted on 2/20/2009 at 10:03 PM

Thank you! Much appreciated!

Heh, the 25th is the day after Mardi Gras. I may be too sick to play. ;)

Comment 9 by Simon Horwith posted on 2/25/2009 at 1:09 AM

Any thoughts about integrating the new Google Docs support with Lighthouse? Just a thought.....

Comment 10 by Raymond Camden posted on 2/26/2009 at 3:11 AM

How? I don't see the connection?

Comment 11 by Josh Orvis posted on 3/5/2009 at 11:53 AM

This is awesome Ray. I was just suggesting to my boss that we consider maintaining all of the writing for our biggest conference within Google Docs, and the only part I felt vulnerable about was leaving all of this vital data sitting on someone else's server.

Being able to schedule an automated backup of those documents will mean that this proposal is pretty much a rock-solid plan.

I'll let you know how it goes.