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("","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 =[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 developer advocate for HERE Technologies. He focuses on JavaScript, serverless 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