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?

Comments

Dave Cohen’s picture

Category: feature » task

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.

Dave Cohen’s picture

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.

pribeh’s picture

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.

Dave Cohen’s picture

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.

pribeh’s picture

Thanks Dave. I'll hold off on requesting any new features for the D5 version.

pflame’s picture

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.

Dave Cohen’s picture

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.

pflame’s picture

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.

deltab’s picture

this works: http://drupal.org/project/facebook_stream, requires Fbconnect, though

Dave Cohen’s picture

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:


/**
 * 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,
                               ));
    }
  }
 
}
almaudoh’s picture

Status: Active » Needs review

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.

pyrello’s picture

Here is a link to the instructions posted in another thread for setting this up: http://drupal.org/node/235457#comment-2321222

georgedamonkey’s picture

I was able to get this working on my site. Thank you!!

Is there any way to make this post to the facebook application's wall, rather than my own? Or, in addition to?

georgedamonkey’s picture

Figured it out. Modified the function a bit:

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'))));
      $target_id = xxxxxxx;
      $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,
                                     'target_id' => $target_id,
                               ));
    }
  }
}

Just replace target_id with your app id.

Dave Cohen’s picture

Status: Needs review » Fixed

Cool nice tip!

I'm resolving this to keep the issue queue clean. As issues arise with fb_stream.module, as they undoubtably will, submit new threads.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

JYW Enterprise’s picture

Dave,

I'm not sure if this where I should post this question, but for lack of that knowledge I will give it a go here.

I am curious if the core of your module could fulfill this ascenario:

Sites like Twitter, Facebook and the like, have APIs which allow you to push and pull content from their respective sites to be shown on blogs and other sites. I am currently developing a community site where i would like people to be able to push and pull content from that community to and from other sites.

I'm not sure if you module covers all those capabilities (as I honestly have not looked under the hood as of yet), but I am wondering if you believe you have the foundation to create an API framework to make remote calls for read and write possible.

Thanks.
Bill

bryanb229’s picture

Thanks George, that was a huge help.