There are a few heavyweight modules contending to provide Facebook integration for Drupal. Which module is right for you? Simply looking at the Reported installs and Maintenance Status won't present a clear answer.
A recent project of mine required the use of Facebook's OAuth service. Here are the three modules that I considered:
I installed and configured each of these modules before coming to a decision. Here's a quick summary of what I found:
Drupal for Facebook
is still very much in development. It isn't production ready, so if you're not willing to contribute, you may want to cross it off the list. Beyond that, it's important to realize that DFF's strength lies in providing a rough framework for using Drupal to build Facebook Applications. It is not ideal (or intended) for providing polished Facebook features to a pre-existing Drupal site. If you're looking for a good launch pad for some serious Facebook App development, give it a shot-- it may be just what you need. Otherwise, you may want to consider another module.
Facebook Connect
provides a number of unique out-of-the-box Facebook features, like finding Facebook friends on your Drupal site, or publishing a customizable message on their Facebook feed. However, this module is still in beta— it is not in a stable state. It should also be noted that FC uses the Facebook Javascript SDK, which means that you need to be familiar with the SDK if you'd like to extend the module's functionality.
Facebook OAuth
is best described in its author's own words, "This module is built with simplicity and flexibility in mind, it provides login services (and does it well), and an API for performing any other actions you may want to write yourself to query against Facebook's APIs."
After attempting to extend Drupal for Facebook and Facebook Connect, Facebook OAuth was like a breath of fresh air. It's simple and flexible, and best of all, you don't need to learn Facebook's Javascript SDK to use it! Facebook OAuth has a well documented and well designed API that any PHP (particularly Drupal) programmer would be comfortable with. Some key features include:
Before I jump in, take note that you can find detailed information about all of FBOAuth's API functions in fboauth.api.php, which is bundled with the module. And don't forget to read the README.txt!
Now let's run through a quick example of how you can utilize the API.
Facebook OAuth allows you to import values from a user's facebook account and map them to that user's Drupal account during registration. In addition to providing a nice GUI for this mapping, it also allows you to define custom field types and callbacks for accomplishing the mapping and for processing the data. Most popular field types are supported by default.
For my site, I wanted to import a user's facebook address to an addressfield and geocode the location for storage in a geofield. By default, FBOAuth does not support mapping to fields of type addressfield. No problem! We'll use a few handy hooks to add that ability.
First, I want to let FBOAuth know that it can map Facebook location information to fields of type addressfield. I'll use hook_fboauth_user_properties_alter() to do that:
/** * Implements hook_fboauth_user_properties_alter(). */ function grasmash_fboauth_user_properties_alter(&$properties) { // Allow the location property to be mapped to Addressfield typed fields. $properties['location']['field_types'][] = 'addressfield'; }
That was easy. Some detail:
Next, let's tell FBOAuth what it should do with data that's been mapped to an addressfield by defining a callback that will process the data.
/** * Implements hook_fboauth_field_convert_info(). */ function grasmash_fboauth_field_convert_info_alter(&$convert_info) { $convert_info += array( 'addressfield' => array( 'label' => t('Address Field'), 'callback' => 'grasmash_fboauth_field_convert_location', ), ); }
If you're familiar with Drupal's array-heavy architecture, this snippet shouldn't surprise you at all. We're just adding another row to $convert_info. It specifies the name of the function that FBOAuth should look for when dealing with an addressfield. Now let's actually create that function!
/** * Facebook data conversion function. * Converts an incoming Facebook location (which is an object) into an array compatible with the addressfield module. */ function grasmash_fboauth_field_convert_location($facebook_property_name, $fbuser, $field, $instance) { $value = NULL; if ($field['type'] == 'addressfield' && isset($fbuser->location) && module_exists('geocoder')) { $geodata = geocoder('google', $fbuser->location->name); foreach ($geodata->data['geocoder_address_components'] as $key => $components) { switch($components->types[0]) { // Set city. case 'locality': $value['locality'] = $components->short_name; break; // Set state. case 'administrative_area_level_1': $value['administrative_area'] = $components->short_name; break; // Set country. case 'country': $value['country'] = $components->short_name; break; } } } return $value; }
Clearly, this will be completely different for fields of any other type. The example above is specifically tailored for populating addressfield fields, and it relies entirely on the output returned by the geocoder module. If you're looking for some guidance in creating your own callback, just look at some of the default callbacks in fboauth.field.inc, like fboauth_field_convert_text().
The last step is to simply configure which field on the user object FBOAuth should actually import the data to. That is done through FBOAuth's admin page, located at admin/config/people/fboauth.
From the README.txt:
"The Facebook OAuth module provides an API for executing queries against Facebook's vast store of user data." The README.txt goes on to explain the workflow for this process, and how you can write your own custom actions.
I plan to write a subsequent blog post about how you can programmatically execute these custom actions, but that's for another day!
Enjoy!

Comments
Paolo Mainardi
Tue, 05/08/2012 - 01:34
Permalink
Very nice article
Thanks for sharing!
CHANDRA
Tue, 05/08/2012 - 03:21
Permalink
THANQ U ,
ITS VERY HELP FULL
drupaljoe
Tue, 05/08/2012 - 05:27
Permalink
Thankyou
I literally tried Drupal for Facebook and Facebook Connect yesterday and they didn't provide what we required. First time hearing about Facebook OAuth when reading this and just tried it out - BRILLIANT module!
Paulius
Tue, 05/08/2012 - 06:37
Permalink
Nice tutorial
Just what I needed, been struggling with Drupal for Facebook and other similar modules (basically was stuck on external libraries and errors around them). Great to see this straightforward module. Thanks again!
Mark Ferree
Tue, 05/08/2012 - 10:19
Permalink
Great comparison would love some more feedback on wiki
There is an existing wiki over at http://groups.drupal.org/node/65268 and I would love to see it get some love to help out the next people facing down this decision.
modhura
Wed, 07/18/2012 - 00:14
Permalink
logout from fb
I have implemented the Facebook OAuth module to my site..On clicking the logout '/user/logout' link user gets logged out of Drupal but on clicking the fb button that user gets logged in.........facebook logins are not asked..which means the user didnot get logged out from fb.... how to do this logout?
bluhring
Sun, 08/12/2012 - 08:54
Permalink
hook for field_convert_info_alter never fires
Thanks for this article!
I get the mytheme_fboauth_user_properties_alter() function to fire, but using a watchdog() alert, it seems that the mytheme_fboauth_field_convert_info_alter() never seems to execute.
As such it allows me to select the field I want to map, but it never maps it.
Anyone experiencing the same problem?
I'm using Drupal 7.14 with AdressField 7.x-1.0-beta3, with geoPHP 7.x-1.4 and geoCoder 7.x-1.1
Thanks!
madmatter23
Sun, 08/12/2012 - 18:17
Permalink
@bluhring
@bluhring
Have you tried placing the hook in a module rather than in a theme template.php file?
bluhring
Mon, 08/13/2012 - 20:34
Permalink
I have not tried that. Still
I have not tried that. Still relatively new to Drupal, but come from a strong programming background... I didn't know that if a hook didn't fire in template.php that it might as a module. Will try to give that a shot.
Thanks for the advice!
bluhring
Tue, 08/14/2012 - 16:07
Permalink
Module Attemp
I've moved the two functions to a module (and enabled it), but they still don't fire... When in a module, do I need to do anything other than name them correctly?
I'm also looking at your "Part 2" article on importing photos... Using watchdog() alerts I see that the mymodule_fboauth_actions() method fires just fine, and it adds the photo setting in the FBOauth settings area.
But the mymodule_fboauth_field_convert_info_alter() and mymodule_fboauth_field_convert_location() never fire the watchdog() alert, nor do I ever see it change my user data.
...thought... If my user account was already created, and then I connect it to FB, does the xxxx_field_convert_info_alter() still apply... or is it just for new accounts?
bluhring
Wed, 08/15/2012 - 18:09
Permalink
Oops...
Sorry for the questions. I actually got this working now. Had an issue with one of my functions having a typo in the name... I think it went unnoticed because I was using a pre-existing account, but when I tried a clean user never having been on the site, it worked like a charm!
madmatter23
Mon, 08/20/2012 - 09:51
Permalink
Glad you got it working!
Working on something for hours, only realize that you made a typo. I've been there.
Anonymous
Sun, 09/02/2012 - 15:09
Permalink
Hi madmatter23!
Hi madmatter23!
Thanks for sharing this -- it's been incredibly useful. I'm trying to do the same type of integration you did with addressfield with Name Field, but I'm missing a bit of a step. One of your code comment reads "Converts an incoming Facebook location (which is an object) into an **array compatible with the addressfield module**." If you have a moment, would you explain where one would look to find the array format necessary for a field type defined in another contrib module (say, for example drupal.org/project/name)
Thanks!
madmatter23
Wed, 09/05/2012 - 11:53
Permalink
Sure
First, I created a new node using the field in question. Then, I used the devel module to look at the node's properties. That reveals the structure of each field. If you need to quickly recreate the array structure in php, devel's dvm() function is a great improvement to print_r().
Rajesh
Mon, 12/17/2012 - 06:02
Permalink
FB Login
Nice tutorial. Is there any way to open fb-login window separately.
Teody C. Seguin
Thu, 01/10/2013 - 23:22
Permalink
Thanks for the tutorial. This
Thanks for the tutorial. This is one of the issue I haven't touched yet seriously. I didn't expect that it is easy :)
Rosamunda
Sat, 02/09/2013 - 17:14
Permalink
Anonymous... remaining anonymous in Drupal?
Hi there!
Thanks for a so very much needed explanation of these modules!!
I didn“t understand something though: May I use FB OAuth to let anonymous users (ie. comment) logging in in their FB account but without creating an account in the Drupal site?
Thanks!
Rosamunda
Mohamed
Mon, 03/25/2013 - 07:05
Permalink
Drupal Facebook Modules
I implemented the facebook OAuth module to my current project. I get it some error after installing this module..On clicking the logout '/user/logout' link user gets logged out of Drupal but on clicking the fb button that user gets logged in.
Gaurank
Mon, 04/08/2013 - 09:20
Permalink
Can You share with me a
Can You share with me a complete video for Facebook Integration In MY site PLz
Add new comment