Integrating Drupal Nodes with your Facebook Stream
You want to promote your website and bring more fan base to your site. A great way to do this is to integrate Facebook with your website, basically using Facebook as a RSS feed.
What you want to do with your drupal website is to have a setting so that when you publish a node, it would post to your Facebook account so that subscribers would be able to view your new content and know to go visit your site.
To accomplish this I would recommend you to use the module Drupal for Facebook and enable the “Drupal for Facebook Stream” that is included with the module. Once you have properly installed it you will need to create another custom module to actually use the Facebook API to post to an account.
Follow the instructions on Publishing to Facebook Wall to set up your custom module.
From the code found in Publishing to Facebook Wall, fb_stream_publish_dialog() actually uses the function FB.Connect.streamPublish(), which prompts a user to login and share content. A good read on this function would be Implementing Feed Publishing form your Website or Application
I have also had to implement this feature using the Facebook Connect module. Since it already has the Facebook library, I just had to call the FB.Connect.streamPublish() function in javascript. Here is sample code of a function I created to post a teaser about a node.
function post_to_facebook($node) {
global $base_url;
if ($node) {
$site = variable_get('site_name', $base_url);
$autopublish = 'true';
$feed_js = array(
'name' => $node->title,
'href' => url('node/' . $node->nid, array('absolute' => TRUE)),
'description' => $node->teaser,
'properties' => array(
t('read') => array(
'text' => $node->title,
'href' => url('node/' . $node->nid, array('absolute' => TRUE)),
),
t('visit') => array(
'text' => $site,
'href' => $base_url,
)
),
);
$actions = array();
$actions[] = array('text' => t('Read More'), 'href' => url('node/'.$node->nid, array('absolute' => TRUE)),);
}
drupal_add_js('$(document).ready(function() {FB.Connect.streamPublish("", '.drupal_to_js($feed_js).', '.drupal_to_js($action_links).', "", "'.t('Something to say?').'", "", '.$autopublish.');});', 'inline', 'footer'); }
What I really like about this implementation is the ability to not have to be logged into a drupal account, they just need to login to their facebook account. Enjoy!






