The installation of Drupal for Facebook is not the same as all other Drupal modules. So please pay close attention to the steps below.
Download
You will need to download two files:
- The Drupal for Facebook project file from http://drupal.org/project/fb. Choose the appropriate version for your version of Drupal.
- Facebook's PHP SDK libraries here: https://github.com/facebook/facebook-php-sdk
Unpack
- Unpack the most recent release of the FB module into /sites/all/modules/fb directory on your server.
- Unpack Facebook's most recent PHP SDK libraries into the /sites/all/libraries/facebook-php-sdk directory on your server.
If for some reason you need to install Facebook's libraries in some other directory on your server you must tell modules/fb where to find it. Edit your settings.php to include a line similar to this (add this to the end of section where the $conf variable is defined and hange the path to exactly where you placed facebook.php):
$conf['fb_api_file'] = 'sites/all/libraries/facebook-php-sdk/src/facebook.php';
Theme Change
In order to support Microsoft Internet Explorer (IE) it is necessary to make this small change to your theme. If you're not using IE right now you can come back to this later. If you are using IE you might want to re-evaluate your whole life and also make this change.
In order to display XFBML tags IE requires the attribute: xmlns:fb="http://www.facebook.com/2008/fbml"
in the <html>
tag, which is part of your theme. Manually edit your theme's page.tpl.php file, adding that attribute alongside the others in the <html></tag>
.
The final tag might look like:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language ?>" lang="<?php print $language ?>" xmlns:fb="http://www.facebook.com/2008/fbml">
Note the exact tag will vary depending on the theme you use. So it is best to find the <html>
tag near the top of page.tpl.php and edit it, adding just: xmlns:fb="http://www.facebook.com/2008/fbml"
to the end of that tag.
Note the page.tpl.php file is still used in Drupal 6, but html.tpl.php has been introduced with Drupal 7 and it is located in modules/system/html.tpl.php and contains the html header information.
Enable the Drupal for Facebook Modules
Under Admin >> Site Building >> Modules, you'll see that Drupal for Facebook comes with a number of modules. For now let's enable just what we need to get started.
- fb.module, listed as "Facebook API". This module alone is sufficient for social plugins such as the Like button.
- fb_devel.module, listed as "FB Development Tools". This module tries to warn you of potential errors before they happen, and has additional tools we'll enable later on. You will need the Devel module as described on the Prequisites page. You should disable fb_devel.module on your live server only after you are certain Facebook features are working.
- Note: In Drupal 7 you will want to enable the fb_app.module (listed as "Facebook Apps") as the fb_devel.module is dependent on it.
Permissions
As always, after enabling a new module, go to Admin > User Management > Permissions and give appropriate role permission to administer applications.
Confirm That It Works
To quickly confirm that XFBML tags now work, place this markup in a page node (or block) on your website. In the body field type in the code shown here:
<fb:like></fb:like>
Note: When placing this markup in a node or block, you must choose an appropriate input format. That means don't leave the default "filtered html", instead choose "full html" or "php". Otherwise, Drupal will strip the <fb:like>
tag before rendering the page. In some cases, even in "full html", you may need to uncheck "Correct faulty and chopped off HTML."
Once you save the configuration, you will see the Facebook Like button as shown below:
Attachment | Size |
---|---|
like-button-logged-out.png | 27.39 KB |
fb-aware-page.tpl_.php-1.png | 27.22 KB |
Comments
Extra script required
I needed to add the line:
to my page (ahead of the XFBML tags) to get the like button to work.
I note that the fb module is adding code to the bottom of the page, that is similar, but not the same as the line I added. Maybe something has changed at Facebook.
Now appears fixed
I have just upgraded to RC13, and my page now works without the extra "script" tag.
James
No, don't add script tag.
Do NOT add a script tag like that. That will cause the JS SDK to initialize without any knowledge of the application you've configured.
Facebook's documentation will often suggest adding a tag like that. But never do that when you are using modules/fb.
Same Issue.
I have to add the script as well to get the like button to work. RC13 doesn't fix this for me.
I had the same problem. Had
I had the same problem. Had to add the script above into my html.tpl.php to get anything facebook related to work. Worth noting I'm on D7
/\
As noted in the issue queue, the script may very well cause other problems. The problem appears to be fixed in 6dev.. not sure about d7.
latest facebook-php-sdk
Just a note here in case it helps someone troubleshoot, the latest facebook-php-sdk (3.0.1 at the time of this writing) actually causes a Fatal error:
Call to undefined method Facebook::getSession() in .../sites/all/modules/fb/fb.module on line 193
Instead, use the php-sdk v2.1.x branch (I used 2.1.2). That worked for me using Drupal 7.2 fb v3.x
thanks edglazer I just
thanks edglazer I just couldn't figure out what the problem was and thought for certain this version used sdk3.
I had the same problem. That
I had the same problem. That must be written in documentation!
similar problem in D7
I had the same problems mentioned here, and I solved using
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"> </ script>
(tanks jlscott) and setting in admin/config/content/formats/full_html unchecking Correct faulty or incomplete HTML. I hope this bug is corrected soon.script bug still an issue???
Just installed this module on a test server (drupal 6).
Installed everything as per instructions, inserted fb tags and nothing.
Added the script tag to the header of my page.tpl and everything starts working.
Is D6 not getting fixes?
FWIW I used this script in the footer to achieve the same result (facebook's preferred method I think - for now):
Until here
Now I am testing with Drupal 7.9 and fb 7x 3x Octuber 2011 and you don't need to add nothing. The like botton work great!!!
FullHTML
If you have Acquia Drupal (7.x), and want to use xfbml, make sure you have unchecked the filters at the FullHTML text format !(http://example.com/admin/config/content/formats/full_html) - Without this adjustment Drupal will strip the
<fb:like></fb:like>
tags ==><like></like>
which are not working... (even if you've selected the FullHTML text format!)Same problem with Bartik theme
Thaks, WhiteX.
Web Software Engineer at
Insem S.p.A. - www.insem.it
Ditto for the Sky theme
I had to uncheck "Correct faulty and chopped off HTML."
D7 Bartik - Uncheck "Correct faulty and chopped off HTML."
You're the man. Thanks bdoyle.
Same problem here! unchecking
Same problem here! unchecking all filters fixed it in Drupal 7
"Notice: Use of undefined constant FB_APP_OP_EVENT..."
Below is the message I got while going through the installation process.
Notice: Use of undefined constant FB_APP_OP_EVENT - assumed 'FB_APP_OP_EVENT' in fb_devel_fb() (line 273 of /hermes/web10/b741/pow.alamave/drupal710lagrohighschool/modules/fb/fb_devel.module).
enable the fb_app module.
enable the fb_app module.
Change Text Formats configure to fix
Home » Administration » Configuration » Content authoring » Text formats
Full HTML and uncheck Correct faulty and chopped off HTML