Facebook Application Development Tips for the Facebook API 

Facebook Application Response Timeout

Have you ever gotten the message The URL [your application url here] did not respond. even when everything seems to be working on your side? One probable reason is that Facebook has a certain response timeout – approximately 12 seconds. If your page fails to respond in this time, Facebook will leave it and display an error message. I used a few simple tricks and managed to work around this issue. Try them out:

Make the Facebook application lighter:

  • The basic idea is to make the page as light as possible on the first load. One way to achieve this is to leave the time consuming tasks like database interaction for later, updating the page with AJAX. (more info)

Speed up your Facebook app:

  • You can use "Preload FQL", that is to send your FQL requests along with the first call, thus making one less roundtrip to the server. (more info)
  • Facebook provides a Batch API. With this API, you can combine multiple API calls and send them together as one call. (more info)
  • You can do the same thing with multiple queries. Wrap, send, and receive them as one using Fql.multiquery. (more info)

AJAX calls have the same timeout issue (although the timeout here is approximately 13 seconds). Additionally all AJAX calls pass through the Facebook server which slows them down. The result is the following JavaScript error: "error":1349011,"errorSummary":"Failed to fetch app Ajax" .

I found a simple solution to avoid it: Use FBJS AJAX and a timer to abort the request when it reaches the time limit and send a new one.

Facebook API Response Time and Error Count

The Facebook API itself sometimes has latency issues causing your app pages to be fetched slower, increasing the risk of reaching the response timeout. Errors in request to their servers are also known to happen. You should always be informed about the Facebook Platform Status.

Syntax Limitations in FQL

The Facebook API allows you to make your own queries using a query language similar to SQL. There is a list of tables you can access (you can only view information; you are not allowed to update the information in any of these tables). You can easily make your own queries, but you should keep in mind that you cannot do a number of normal (for SQL) things such as join tables, use 'distinct', 'limit', 'group by', etc., or use "from" against more than one table. You can easily do these operations in the code, however. Combined with the use of the multiquery functionality, things should work almost as fast as if you were using pure SQL.

Facebook API Changes

As you may guess, the Facebook API still is in development, so you should keep yourself up to date with the constant changes in its platform. Some of these changes are potentially breaking, some features are being deprecated or changed, and some cool new things are being added. It is useful to read the Facebook Developer Roadmap to be informed for the specific changes that have been planned and when to expect them. Here are some of the upcoming ones:

  • an open source, faster, slimmer, and more efficient JavaScript Library will be developed - I am personally looking forward to this. It will be of great help, as right now the FBJS is very limited.
  • profile boxes, application info sections, and the Boxes tab will be removed – If you want to integrate into the user's profile, you will be able to do that only with Application tabs.
  • formatting on canvas pages will be changed to better highlight an application's brand – For now, I myself am using fb:dashboard. It not only gives you clean app navigation, but also a great look by positioning the name and icon of your app nicely on every page.

Until recently, some of the API changes, even when prepared for them, had unexpected effects on some applications (in some cases, bugs appeared) and there was nothing we could do about it. In late February, Facebook introduced a tool to help us prepare for the changes – the Migrations tool. When Facebook announces a new feature or fix, you can first do some testing before going to the Migrations tab in your application settings and choosing to enable it (it is disabled by default).

In conclusion, I can assure you that whatever problems you may stumble upon there is a huge community of developers willing to help you out. Just go to the Facebook Developers Forum. There is also lots of documentation and useful tips in the Facebook Developers Wiki. Have fun!

Teaser: