Google Docs CFC

This post is more than 2 years old.

Yesterday I posted a quick example of integrating Google's Docs API with ColdFusion. I went ahead and wrapped up the code in a simple set of CFCs. There is a base CFC that handles authentication along with a docs CFC that handles the real interaction. Here is some sample code:

<cfset docs = createObject("component", "docs")> <cfset docs.authenticate("rcamden@gmail.com","foo")>

This creates an instance of the CFC and logs the user on. If authentication fails, a CF error is thrown, so normally this would probably be wrapped in cfry/cfcatch.

To get all your documents, you would run:

<cfset mydocs = docs.getDocumentList()>

This returns a query. One of the columns contains the sourceurl, which can be used to grab the source:

<cfset content = docs.download(mydocs.sourceurl[1])> <cfoutput>result is #content#</cfoutput>

The getDocumentList() supports 2 filters (Google supports more). You can use max to limit the number of results:

<cfset mydocs = docs.getDocumentList(max=9)>

You can also apply a title filter:

<cfset mydocs = docs.getDocumentList(title="Blog")>

The title filter is a search, not a direct match.

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 John posted on 12/8/2007 at 10:32 PM

Ray, you the man, thanks for the code...

Comment 2 by Kostas posted on 5/10/2011 at 4:50 PM

Hi Ray,

Thanks a lot for the code.

Question: How can I add a function for uploading docs?

I have created a kind of a forum and the thread creator can upload docs using his gmail login and then the other users can view the docs 'attached' on the thread and edit them.

Thanks to your cfc I can read the files bu I also I need the upload function for the thread creation and the edit process as well.

Any quick solution?

Thanks a lot!

Comment 3 by Raymond Camden posted on 5/11/2011 at 1:07 AM

It would need to be written. It's possible. Just not something I've had time to do.

Comment 4 by Kostas posted on 5/11/2011 at 2:09 AM

That's cool.

Thanks for your time.

Comment 5 by John Sieber posted on 2/20/2012 at 10:43 AM

I've used this cfc in a project for a couple of years, but I found that I could no longer use the getDocumentList function. It appears that Google now requires connecting with a secure connections. I modified line 91 of the docs.cfc so that the mainurl variable is now set with https instead of http. Hope this helps someone else down the line. Thanks for the great cfc!

Comment 6 by Matt Connolly posted on 4/11/2013 at 11:51 PM

When I use the "download" function, the content returned just says "Not Authorized". I am not having any problems with the authenticate or getDocumentList functions

Comment 7 by Raymond Camden posted on 4/12/2013 at 5:55 AM

Just tested and it worked fine for me. Here is a demo. With the password changed of course. Note I made the mod John recommended.

https://gist.github.com/cfj...