Getting Started with Facebook Application Development using ColdFusion/Railo

0
89
5 min read

There are other CFML Facebook articles on the internet such as Ray Camden’s tutorial with ColdFusion 8; however Facebook continues to innovate and change, and a majority of those resources are out of date for Facebook’s 2010 updates. Things such as “profile boxes” are passé, and now you have to work with “Application Tabs.” In addition, I have found that there are some general concepts of how Facebook applications work. These have not been covered well in other resources.

Why Facebook?

According to statistics, Facebook is the 3rd highest traffic site in the US right now (statistics for the rest of the world weren’t readily available). The nature of Facebook is that people socialize, and look at what other people are doing, which means that if your friends post that they are using certain applications or visiting certain sites, you know about it, and for most of us, that’s a good enough reason to check it out.  Thats what’s called Grass roots marketing, and it works.

“The average U.S. Internet user spends more time on Facebook than on Google, Yahoo, YouTube, Microsoft, Wikipedia and Amazon combined.”

That should tell you something. There is a big market to tap into, and should answer the question—why Facebook. Even if you think Facebook isn’t a useful tool for you, you can’t argue with the numbers when it comes to reaching potential customers.

Why CFML with Facebook?

Hopefully your interest in ColdFusion and/or Railo answers this. Since CFML is such an easy to learn and powerful extensible programming language, it only makes sense that we should be able to build Facebook applications with it.

There are always some cautions with making websites talk to each other. Using CFML with Facebook is no different; however most of these have been overcome by people already, and you can easily zip through this by copy/pasting the work of others. The basic framework for my applications is the same, and you can use this as your jumping-off point to work on your own applications.

Understanding Data Flow

Facebook is rather unique in how it is structured, and understanding this structure is critical to being able to build applications properly. You will save yourself a lot of frustration by reviewing this section before you begin writing code.

In most websites or web applications, people type in a web address, and they connect directly to your web server, where your application handles the business logic, database interaction and any other work, and then gives web content back to the requesting user.

This is not the case with Facebook. With Facebook applications, users open up their web browsers to a Facebook web address (the “Canvas URL”), Facebook’s servers make a “behind the scenes” request to your web server (the “Callback URL”), your application then responds to Facebook’s request, and then, Facebook does the final markup and sends the web page content back to the user’s browser.

If you followed that, you see that users always interact with Facebook, while Facebook’s server is the one that talks to your application. You can also connect back to Facebook via their RESTful API to get information about users, friends, photos, posts and more. So here are two important concepts to understand:

  1. Your Facebook application code lives on your web server, separate from Facebook.
  2. You will get web requests from Facebook on behalf of Facebook users.
  3. Users should always be interacting with Facebook’s web site; They should never go directly to your web server

The Canvas URL is a Facebook address, which you will setup in the next section. The Callback URL is the root where you put your application files (*.cfc and *.cfm). It is also where you will put your CSS files, images, and anything else your application needs.

The Callback URL can be a directory on any web hosting account, so there is no need to setup a separate web host for your Facebook application.

Setting up a new Facebook application

Generally speaking, setting up a new Facebook application is pretty easy. There are a few things that can trip you up, and I will highlight them.

The first thing to do is log into your Facebook account, and authorize the Facebook Developer application by going to this URL:http://apps.facebook.com/developer/

Once you have authorized this application, you will see a link to create a new application.

Create a new application, and give it a name:

Fill in the description if you want, give it an icon and logo if you wish.

Click on the Canvas menu option.

Enter the canvas page url (this becomes the URL on facebook’s site that you and your users will go to – apps.facebook.com/yourapp).

Enter the callback URL (the full URL to YOUR web server directory where your CFML code will reside.

Very important: Select Render method to be “FBML” (which stands for Facebook Markup Language).

The other options you can leave as their default values.

When you are done, save your changes.

The application summary page will show you some important information, specifically the API Key and Application Secret, which you will need in your application later.

Consider using Facebook’s “sandbox” mode which makes your application invisible to the world while you are developing it. Likewise, when you are done with your application, consider using Facebook’s application directory to promote your application.

LEAVE A REPLY

Please enter your comment!
Please enter your name here