Need a **current module** example for node post to Facebook wall
Just like the subject line reads.
Yes, I know of the tutorials out there and managed to make some progress. However, these tutorials for the much needed module itself contain deprecated code and outdated versions of the Facebook PHP SDK - which I cannot seem to find.
I'm using:
Drupal 6
Drupal for facebook 6.x-3.2-rc3
Facebook's PHP SDK 3.1.1
A working Facebook book app in my Drupal install
I did manage to get the code below working, however, the code is deprecated, so I'll just have to rewrite in matter of days/weeks/months. Also, it only posts to user's account wall - I'd like to post to a page the user has created.
<?php
/**
* Implementation of hook_form_alter.
*
* Adds a checkbox to node edit and comment forms. This checkbox lets
* facebook users know that content may be published to their Wall,
* and gives them a chance to prevent that.
*/
function nex_auto_post_form_alter(&$form, $form_state, $form_id) {
if (isset($GLOBALS['_fb']) && fb_facebook_user()) {
if ($form['#id'] == 'node-form') {
// Add checkbox to control feed publish.
$form['nex_auto_post']['stream_publish'] = array(
'#type' => 'checkbox',
'#title' => 'Share on Facebook',
'#default_value' => TRUE,
);
}
else if ($form['form_id']['#value'] == 'comment_form') {
// Add checkbox to control feed publish.
$form['nex_auto_post']['stream_publish'] = array(
'#type' => 'checkbox',
'#title' => 'Share on Facebook',
'#default_value' => TRUE,
);
}
}
}
/**
* Implementation of hook_nodeapi().
*
* Publish to facebook Walls when users submit nodes.
*/
function nex_auto_post_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'insert' || $op == 'update') {
if (isset($node->stream_publish) && $node->stream_publish) {
$attachment = array(
'name' => $node->title,
'href' => url('node/' . $node->nid, array('absolute' => TRUE)),
'description' => $node->teaser,
);
$user_message = t('Check out my latest post on !site...',
array('!site' => variable_get('site_name', t('my Drupal for Facebook powered site'))));
$actions = array();
$actions[] = array('text' => t('Read More'),
'href' => url('node/'.$node->nid, array('absolute' => TRUE)),
);
fb_stream_publish_dialog(array('user_message' => $user_message,
'attachment' => $attachment,
'action_links' => $actions,
));
}
}
}
/**
* Implementation of hook_comment().
*
* Publish to facebook Walls when users submit comments.
*/
function nex_auto_post_comment(&$a1, $op) {
if ($op == 'insert' || $op == 'update') {
if ($a1['stream_publish']) {
//dpm($a1, "dff_custom_comment, publishing to stream");
$node = node_load($a1['nid']);
// http://wiki.developers.facebook.com/index.php/Attachment_(Streams)
$attachment = array(
'name' => $a1['subject'],
'href' => url('node/' . $a1['nid'], array('absolute' => TRUE, 'fragment' => 'comment-' . $a1['cid'])),
'description' => $a1['comment'],
'properties' => array(t('In reply to') => array('text' => $node->title, 'href' => url("node/" . $node->nid, array('absolute' => TRUE)))),
);
$user_message = t('Check out my latest comment on !site...',
array('!site' => variable_get('site_name', t('my Drupal for Facebook powered site'))));
$actions = array();
$actions[] = array('text' => t('Read More'),
'href' => url('node/'.$a1['nid'], array('absolute' => TRUE)),
);
fb_stream_publish_dialog(array('user_message' => $user_message,
'attachment' => $attachment,
'action_links' => $actions,
));
}
}
}I think all I need now is the updated API version of the above. Is that documentation available?
I've read Facebook's "documentation" as directed here:http://developers.facebook.com/docs/reference/rest/stream.publish/
That page reads: We are in the process of deprecating the REST API, so if you are building a new application you shouldn't use this function. Instead use the Graph API and POST a Post object to the feed connection of the User object
Yet I can't seem to find a straight forward PHP example for my module using these updated APIs.
Any help would be greatly appreciated.
- Forums:

Check out this patch. It's
Check out this patch. It's designed to post content to one FB wall, on behalf of a site admin. As opposed to what you seem to want, which is on behalf of the currently connected user. I plan for a future modules/fb to support both of those.
http://drupal.org/node/1454736