Drupal for Facebook - changing what is published to facebook Walls when users submit nodes

There is one and only one module you should use when using facebook integration with drupal its Drupal for Facebook(DFF). It has many features but its also a bit harder to setup and use. I won't get into details of this, but you MUST read readme files and all documentation to make it work, you will need to spend some hours learning it :-( but then again you will know it for future and your knowledge will be appliable to many drupal sites. Lets get to the point. I wanted that when i post something to my drupal site, the same post goes to facebook wall of my facebook page. There is a submodule in DFF module called example module, which in fact has some rather nice features and maybe in some future it becomes standard submodule. What you can do here is edit how your posts are posted to facebook wall, you should edit fb_example_nodeapi as this is the place where it is defined what is sent to FB.

So we edit this function and what is sent is defined in $attachment array

$attachment = array(
        'name' => $node->title,
        'href' => url('node/' . $node->nid, array('absolute' => TRUE)),
        'description' => filter_xss($node->teaser, array()),
      );

Node title, node url and node text(teaser), we also want to add image besides fb post. So we add some other code

    $nid_f=node_load($node->field_gallery_ref[0]['nid']);
    $url = url($nid_f->field_image2[0][filepath], array('absolute' => TRUE));
     $attachment['media'][] = array(
          'type' => 'image',
          'src' => $url,
          'href' => $url,
        );

We load the current node data, pass the value of image path to src and href of $attachment['media'] and then we also have a image from our post. This one is from CCK field but you can use whatever you like and send source to FB.

Take attached file for this code already applied.