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.
Archived Comments
Ray, you the man, thanks for the code...
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!
It would need to be written. It's possible. Just not something I've had time to do.
That's cool.
Thanks for your time.
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!
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
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...