Coldfusion Facebook REST API Example.

I've created a quick and very, very dirty example on how to create a Coldfusion application for Facebook. There is no documentation with the project, and it comes as is where is blah blah blah, no warranty, etc. Use at your own risk.

In your facebook application, set it to use an Iframe. I have not yet figured out how to pass the auth_token through a complete FBML application.

There is a REST compatible CFC here

You'll need to add these two functions somewhere to your pleasing in the CFC.

<!---
Created by Cory Johnson on June 13, 2007

For help with this, contact cory@dragonflybytes.com
--->


   <!--- fbml --->
   <cffunction name="fbml_setFBML" access="public" output="false" returntype="any">
      <cfargument name="fbml" type="string" required="yes" />
      <cfargument name="sess_key" type="string" required="yes" />

      <cfset var result = "" />
      <cfset var params = StructNew() />

      <cfset params["markup"] = arguments.fbml/>
      <cfset params["session_key"] = arguments.sess_key/>      

      <cfset result = callMethod("facebook.profile.setFBML", params) />

      <cfreturn result />
   </cffunction>

   <cffunction name="fbml_getFBML" access="public" output="false" returntype="any">
      <cfargument name="sess_key" type="string" required="yes" />
      <cfargument name="uid" type="string" required="yes" />

      <cfset var result = "" />
      <cfset var params = StructNew() />
      
      <cfset params["uid"] = arguments.uid />
      <cfset params["session_key"] = arguments.sess_key />
      
      <cfset result = callMethod("facebook.profile.getFBML", params) />

      <cfreturn result />
   </cffunction>

A small difference between these methods, and those in the REST Client, is that I am not using the XmlToArray function. I prefer Xpath, because it's more like working with an Object. You can change that if you really want to.

The source I made to go with this source is here

Comments
Thanks for posting this. Trying it now.
# Posted By Philip Kaplan | 6/14/07 3:44 PM
Why does it seem my apps can only be "logged into," and not "installed?"

See the screenshot below, of my app vs other Facebook apps. After "logging in" to my app, there's no left-hand nav or anything.

http://www.fbappz.com/fbapps.gif

I definitely set up my app with "Can your application be added on Facebook?" checked. Any ideas?
# Posted By Philip Kaplan | 6/14/07 4:29 PM
Are you testing in facebook, or just against your callback URL?
# Posted By Cory | 6/14/07 5:05 PM
Okay, I figured it out.

I was going straight to the canvas URL (or the callback URL) to install it, instead of going to the "About" page.

ps- Cory rules.
# Posted By Philip Kaplan | 6/14/07 5:23 PM
I just cannot get the ColdFusion Facebook API to work! I have tried everything I can think of to test and understand why it's happening. All I get is this error: " Premature end of file. (An error occured while Parsing an XML document.)" [Line: "<cfreturn XmlParse(cfhttp.FileContent) />"].

So I looked at the code and modified it to get CF to output the direct contents of the CFHTTP request to FB's REST.php and it is always blank!!!

I am just going mad!

Please help!
# Posted By Harry Fear | 6/16/08 12:40 AM
They probably changed the API. I haven't done anything with this in a long time, so probably check the developer forums on facebook.
# Posted By Cory | 6/16/08 8:38 PM
Hi,

Thanks a lot for replying.

I created my own test method and managed to get working. I haven't worked out why that worked and the CFC didn't.

Thanks again.

Harry fear
# Posted By Harry Fear | 6/17/08 1:12 AM
HELP! I am having similar issues... I am stuck on getting this API to work.

Does anyone have a new Client?? Or can they send me some sample code on how to get the Session ID...???

I am not sure what to pass for the valu "sig"

(forgive my ignorance, I am a novice)
# Posted By Rich SWier | 6/29/08 3:55 PM
i was having trouble getting callMethod() to return ANYTHING and i figured out the problem. i suppose FB updated some things behind the scenes, but in callMethod() if you change the method attribute of CFHTTP from POST to GET it works fine.

hallelujah!
# Posted By tim yager | 8/6/08 5:11 PM
That worked for me too.
In the postRequest function, in the cfhttp tag, changed method from post to get.
Many thanks from a facebook noob.
# Posted By RandyF | 9/16/08 4:15 AM