Facebook Application Development


Do you have a Facebook page? If you do, you are among the 600 million users who actively use the social-networking service. I'll admit I initially resisted the temptation to join Facebook. After all, I've got e-mail, instant messaging and VoIP. What do I need with yet another form of communication? Eventually, temptation got the better of me, and I gave it a try. For the record, I also experimented with MySpace and Twitter, but those sites just didn't seem to do anything for me. These days, every time I go to my computer, I check my servers, my e-mail and my Facebook.

I never thought it would get to this point, but it turns out that Facebook is a surprisingly powerful piece of technology. So far, I've connected with friends from church, college, high school, previous jobs and some of my son's activities. I've managed to reconnect with my best friend from high school after 20 years. I've even managed to reconnect with my best friend from the third grade! Since I'm 43 years old, I think that's quite an accomplishment. Like I said, it's very powerful technology.

But for me, there's more. I also get links to blogs and news articles from like-minded friends as well as pointers to breaking news that's of interest to me. Many times, I've heard about events on Facebook before I saw them on TV or read about them in the newspaper. Lately, I've been investigating ways to use Facebook to promote my new business, and I'm sharing some of what I've found in this article.

First, let's take care of some of the easy stuff. Everyone's probably been to a Web site and seen a Facebook "Like" button. When users click on this button, they are asked to log in to Facebook, if they're not already. Then, the button click causes a brief message to be added to users' Facebook pages, indicating that they like the particular Web site. All of the users' Facebook friends then can see this message. Assuming that many of one's friends share the same interests, this is a very simple way to get a message out to potentially interested people.

Adding a Like button to a Web site is as easy as embedding a little HTML code into your page. Facebook even has a wizard to help customize the button: https://developers.facebook.com/docs/reference/plugins/like.

When I played with this wizard, I was given code that looked like the code shown in Listing 1. This code results in a Web browser displaying something that resembles Figure 1.

Listing 1. Like Button Code

<iframe src="http://www.facebook.com/plugins/like.php?href=
 ↪scrolling="no" frameborder="0" style="border:none; 
 ↪overflow:hidden; width:450px; height:80px;" 

Figure 1

Figure 1. Like Button

Facebook also provides methods that allow a Web site to post to users' Facebook pages as well as adding a person or page to their friends list. These methods are documented at https://developers.facebook.com/docs/reference/dialogs.

Before I go any further, let me pass on a little tidbit of information I came across while researching this article. Facebook supports a primitive chat function that allows users to exchange interactive messages with their friends. This chat function is based on the XMMP protocol, which is the same protocol that Google Talk and Jabber use. The details are documented at https://developers.facebook.com/docs/chat. Essentially, you need to know your Facebook user name and password. Then, you prepend your user name to @chat.facebook.com to form a Jabber ID. When I plugged this information in to Kopete, I was able to chat with my Facebook friends using Kopete. I also was able to get real-time updates when my friends logged in and out of Facebook.

Facebook also provides a powerful method of querying its database for various types of information. Using a language called Facebook Query Language (FQL), you can ask for all kinds of information about a Facebook user, subject to access restrictions. The easiest way to do this is to use the HTTP GET access method. This method allows you to execute a query using a standard HTTP GET. The results are returned in XML format. All you have to do is append your query to the end of this URL: https://api.facebook.com/method/fql.query?query=.

For example, if you had a user ID number and wanted to find the user's full name, you would use something like this:

 ↪name from user where uid=1690577964


Amazingly, your results look like this:

<fql_query_response list="true">
               <name>Mike Diehl</name>


FQL requires that you specifically list each of the fields in which you are interested. That means you can't simply use select * from... as you would be tempted to do in a language like SQL. So, it's important to know what tables and columns are available to you. This is well documented at: https://developers.facebook.com/docs/reference/fql.

At the risk of duplicating what's already on the Web site, here's a list of a few of the more interesting tables that you can query (from the Web site):

  • comment: query this table to obtain comments associated with one or more feed comment XIDs.

  • connectioncomment: query this table to return a user's friends and the Facebook pages to which the user is connected.

  • friend: query this table to determine whether two users are linked together as friends.

  • like: query this table to return the user IDs of users who like a given Facebook object (video, note, link, photo or photo album).

  • notification: query this table to get the notifications for the current session user—that is, any notification that appears on http://www.facebook.com/notifications.php.

  • profile: query this table to return certain (typically publicly) viewable information from a user's profile or Facebook page that is displayed in a story.

  • status: query this table to return one or more of a user's statuses.

  • stream: query this table to return posts from a user's stream or the user's profile.

  • user: query this table to return detailed information from a user's profile.

You can query against quite a few other tables, and I've not fully explored what information is available. I can tell you that e-mail addresses and phone numbers aren't readily available using this query method. Also, users are able to set permissions that determine what can be retrieved.

That said, you could use these methods in a server-side program to get all kinds of information about a user. But, the real power comes from being able to perform these queries on the client's computer via JavaScript. (I'll show you how that's done, shortly.)


Mike Diehl is a freelance Computer Nerd specializing in Linux administration, programing, and VoIP. Mike lives in Albuquerque, NM. with his wife and 3 sons. He can be reached at mdiehl@diehlnet.com


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Sounds really interesting.

managed services's picture

Sounds really interesting. I'm new in fan page development platform. Hope you guys very friendly people. I just need to learning several development apps. Thanks!

NIce info

Anonymous's picture

hi i am new in the development field your blog read i have create my pluging in the facebook.


blinds's picture

How did you do that?

I've had issues with LINUX

johngaltrules's picture

and its ability to render 3D graphics in AutoCAD. Any suggestions?

Really? ... '↪' character used in API calls?

Brendan Kidwell's picture

In listing 1, you've got the entity RARRHK ('↪') all over your iframe element. Does the Facebook API really use that, or is this some weird CMS data corruption going on in linuxjournal.com?


MikeDiehl's picture

Looks like the transition from print to CMS has corrupted the listing. Simply delete the entity and you get what SHOULD be there.