Integrating Drupal and Facebook

James Walker (see his bio in Contributors)

Problem

I have an existing site built with Drupal (http://drupal.org/) and I’d like to create an associated Facebook application quickly and easily. It’s important to be able to reuse the existing content and user base for the new application.

Solution

Drupal for Facebook (http://drupal.org/project/fb) is an existing Drupal module with an associated FBML theme that can quickly and easily create one or more Facebook applications for an existing site.

Discussion

To begin, create your application on Facebook as you normally would, but leave the callback URL blank for now.

Next, download the Drupal for Facebook module from http://drupal.org/project/fb and install it per the included README.txt. The instructions here include downloading a copy of the Facebook PHP library and installing the associated FBML theme.

Once those steps are complete, it is time to enable some modules. The Facebook for Drupal package comes with several modules so that you can enable only the modules your application requires. A good starter set is “Facebook API,” “Facebook Application,” “Facebook Application Canvas Pages,” and “Facebook User Management.” Note, however, that there are modules for integrating things like the popular Views and Actions modules for Drupal.

Now we’re ready to create applications. Go to Create content→Facebook Application, and fill out the form with information about the application you already created, such as the API Key, secret, and the app ID. You can also specify controls around user account handling and landing pages for users.

When that form is submitted, Drupal will generate a full callback URL that you can then use in the application settings on Facebook. Drupal will also generate Post-Add and Post-Remove URLs as well.

Congratulations! Your Drupal site is now a Facebook application.

For more information and hints on additional features and configuration, see http://drupalforfacebook.org/ and the screencasts available at http://www.dave-cohen.com/node/2246.

Get Facebook Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.