Open Stream API integration
frankcarey - April 28, 2009 - 18:57
| Project: | Drupal for Facebook |
| Version: | 6.x-2.x-dev |
| Component: | Miscellaneous |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Jump to:
Description
Drupal announced/released a new API for the feed yesterday
http://developers.facebook.com/news.php?blog=1&story=225
It allows apps to get hold of the whole feed, pictures, videos and all it looks like. Dave, did the Knight foundation grant open any of your time to tackle this?

#1
Agreed this needs to be done. Basically everything in fb_feed.module needs to change to this API.
The problem with the facebook api is that some part of it is changing in a major way all the time. It's a struggle to keep up.
The knight foundation grant has a budget that does not take all this into account. Because I'm not psychic. I'm still looking for chip-ins and patches to help out.
thanks for the link. I was just reading about this stuff earlier today.
#2
Rather than change anything in fb_feed.module, I'll make a new module called fb_stream.module and deprecate fb_feed. Not sure how soon I'll get around to it, however.
#3
Where can I make a chip-in Dave? I really want a fb_stream.module for D5 but can't seem to figure out how to help much code-wise.
#4
To contribute towards a specific issue like this, make a pledge on drupalforfacebook.org, or read more about sponsorship options.
But I'm not sure a stream module for D5 is in order. I'm targeting D6 for all new features, it's hard to maintain both branches. The stream stuff is very new and still requires extended permissions which your app users must opt into. Is there something specific you need? Because in D5 you can already write messages to the feed.
#5
Thanks Dave. I'll hold off on requesting any new features for the D5 version.
#6
Hi Dave,
I would like to implement this fb_stream.module. Let me know if you have already started implementing this. If you started already, tell me how I can help you finish this module.
#7
I have not started to implement. Feel free to take a stab at it. I doubt the fb_feed module will go away, as it defines a content type for templates. So it's unclear to me whether the stream code belongs in there or not. But if you create an fb_stream module with some good code, we'll figure out the right way to add it.
#8
Hi Dave,
I will go through the stream api and will figure out what needs to be done. Based on that I will write module and will keep you update on the progress.
#9
this works: http://drupal.org/project/facebook_stream, requires Fbconnect, though
#10
I've just checked in fb_stream.module. It's a start. Please help me improve it.
It does not do everything that fb_feed.module does, and it never will. For one, it does not need to support templates. For two, it may never support actions. Does anyone really use those anyway? And the new api does not do template substitution, so I'm not sure it needs the same treatment.
The Open Stream API does a lot of things. Right now this module only does the tip of the iceberg, which is to invoke the publish dialog. I welcome patches that expand it's functionality. It would be cool to (a) not have to write code to use this, and (b) do a lot more, like adding comments on facebook walls when comments are added to Drupal; or anything have to do with reading streams.
Right now, drupalforfacebook.org uses this module to publish when you post to the forum or submit a comment. It does this via a custom module, implemented this way:
<?php
/**
* Implementation of hook_form_alter.
*/
function dff_custom_form_alter(&$form, $form_state, $form_id) {
//dpm(func_get_args(), "dff_custom_form_alter($form_id)"); // debug
if (isset($GLOBALS['fb']) && fb_facebook_user()) {
if ($form['#id'] == 'node-form') {
// Add checkbox to control feed publish.
$form['dff_custom']['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['dff_custom']['stream_publish'] = array(
'#type' => 'checkbox',
'#title' => 'Share on Facebook',
'#default_value' => TRUE,
);
}
}
}
function dff_custom_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'insert' || $op == 'update') {
if ($node->stream_publish) {
//dpm($node, "dff_custom_nodeapi, publishing to stream");
// http://wiki.developers.facebook.com/index.php/Attachment_(Streams)
$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,
));
}
}
}
function dff_custom_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,
));
}
}
}
?>
#11
Hi Dave,
I'm also interested in a fb_stream.module for my current project. I'll see how I can contribute code-wise. However, I can't commit to a timeline. I'd also like to borrow your custom implementation code.