! NOTICE ! Facebook have depreciated their old SDK that powered the Drupal for Facebook functionality discussed in this post, so at present, this will not work. We will be updating the how-to shortly to take account of the new API and with a Drupal 7 example ! NOTICE !

So, with scant documentation on this very important piece of functionality I thought I'd post a 'how to' on this one - you want to automatically push content from your Drupal site, into a Facebook wall, fan page or company page, and you want to do this as the page itself rather than as your user?

Here goes...

1. Create a plain Facebook application.

Head to https://developers.facebook.com/apps and create an application with bare minimum details.

Image removed.

The icon you upload will be the icon that appears at the base of each Facebook wall post, beside the details. The profile image you upload will appear on the application page.

Make note of your 'App ID' and your 'App Secret'.

2. Install Drupal for Facebook.

In the normal manner, downloading, unpacking and putting in your modules directory.

3. Download and install the Facebook SDK.

Be sure to dowload a version earlier than 3.0 as the latest versions are not compatible. We have had the most joy with the 2.2 version.

You will need to place the unzipped 'src' directory so that the directory structure looks like :-

/sites/all/libraries/facebook-php-sdk/src/ and then the individual files.

4. Enable and configure Drupal For Facebook in Drupal.

Got to your Site Building -> Modules -> List and enable all the Drupal for Facebook modules.

You will also need to enable the Facebook Extended Permission module in the Drupal for Facebook - Contrib modules fieldset.

You need to add 'xmlns:fb="http://www.facebook.com/2008/fbml"' at the end of your theme's opening html tag. So, it will look something like :-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" lang="<?php print $language->language; ?>" dir="<?php print $language->dir; ?> xmlns:fb="http://www.facebook.com/2008/fbml">

You need to add these two lines to the bottom of your settings.php file

include "sites/all/modules/fb/fb_url_rewrite.inc";
include "sites/all/modules/fb/fb_settings.inc";

Or, depending where you install your modules, this might be

include "modules/fb/fb_url_rewrite.inc";
include "modules/fb/fb_settings.inc";

All of these settings (step 4) are in the readme.txt in the root of the directory of the Facebook module, if stuck, that's your first stop!

5. Create Your Application in Drupal for Facebook

Head to Site Building -> Facebook Applications -> Add App.

Fill out a label, put in your previous App ID and App Secret, ensure 'enabled' is ticked.

Under 'Facebook Extended Permissions -> Required Extended Permissions', tick the boxes for 'Offline Access', 'Publish to my Wall' and 'Manage Pages'.

Under 'Facebook Connect' ensure that the Primary checkbox is ticked.

Save the application.

6. Link your application to Facebook Connect.

Head to Site Building -> Facebook Applications -> Facebook Connect

From the dropdown, select your new application and save.

7. Connect your Drupal account to your Facebook account.

You will need to place the Facebook Connect block somewhere you can get at it, so head to Site Building -> Blocks > List and place the Facebook Connect block in footer or right sidebar (depending where you want it).

Then, when logged in as the account you wish to link (I use the admin account), click on the Facebook Connect icon and then login to Facebook on the popup allowing the application access.

Image removed.

Double check at this point that all the things you ticked in 'Extended Permissions' are showing, if they are not, if it is just 'access my basic information', then you need to go back and edit the app to enable the extended permissions mentioned in step 5.

8. Install and configure your custom Facebook Wall Post module.

This is the tricky part where many people fall over. The documentation is sketchy and out of date with conflicting instructions based on different versions of Facebook requirements.

Download and enable your custom Facebook Wall Post module (example at base of this article).

I have included a sample module that will do the job at the bottom of this post. You will need to head to the Drupal menu item - 'Site Configuration -> Facebook Wall Post' to set your configuration items.

If you wish to post custom media types (images/videos/etc) please look in the attachments section of the module code and program accordingly.

If you wish to post on the page wall as yourself, or, on your own wall, please look at the configuration page and set the target_id and user_id accordingly.

You may also wish to restrict which types of content are posted to Facebook, you can do this on the configuration page.

9. Install the application into your Facebook page.

Head to the application's page, you can see this by clicking on 'about' in Site Building -> Facebook applications -> List on your app, or simply go to http://www.facebook.com/apps/application.php?id=YOURAPPLICATIONID.

When on the application page, click on 'Add to My Page' on the left-hand menu, select the page. And close.

This will add the application to your page and a tab, you don't really need the tab. So, I would head to your fan/company page, edit the page, apps, and then 'remove the tab' from the application settings.

You're now ready to post to Facebook!

A 'share on Facebook' link will appear on each post you make, if it's ticked, it will background post to your wall as the wall!

Blog Files