Download & Extend

Publish only custom fields

Project:Drupal for Facebook
Version:7.x-3.3-beta6
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Publish to Facebook work fine but I don't know how to define wich fields would be published.

For example this is what post in Facebook

[IMAGE] MY NODE TITLE Edit Delete CITYDATEETAXONOMYTERMRESUME

I would like to post my custom image and resume fields.

Comments

#1

Before fb_stream.module posts to facebook's graph, it invokes hook_fb_stream($op, $data, &$return).

Look for $op == FB_STREAM_OP_PRE_POST. The &$return contains the data that will be posted to facebook. Your custom hook can modify as needed for your site. You'll have to experiment to get it to look just the way you want.

Please post your snippet here to help others looking for the same effect.

#2

Thanks!

The admin links Edit Delete come from the Contextual Links module you can disable it or use something like that fore more control

<?php

function MYMODULE_fb_stream($op, $data, &$return) {

  //drupal_set_message('<pre>'. print_r($return, TRUE) .'</pre>');

  $resume = field_get_items('node', $data['node'], 'field_resume');

  if ($op == FB_STREAM_OP_PRE_POST) {
    $return['description'] = $resume[0]['value'];
  }
}

#3

And how to define the image to post?

I have one image field to the main image with only one value and another image field with unlimited values for a photo gallery.

When the node have only the main image this is posted fine on Facebook, but when the node have one image in the gallery this is the image posted, and if have more than one none is posted.

Another thing, this error appear after save and in all of the cases above

Notice: Undefined index: uri en theme_image_formatter() (line 602 de /Applications/MAMP/htdocs/pm/modules/image/image.field.inc).

#4

Just FYI, when I need something like

<?php
//drupal_set_message('<pre>'. print_r($return, TRUE) .'</pre>');
?>
, I prefer
<?php
dpm
($return, __FUNCTION__); // dpm() comes with devel.module
?>

To set a picture, something like this may work in your hook_fb_stream(). Customize for your field name.

<?php
     
// Honor the field_story_image.  If present, that is the image facebook should show.
     
$key = 'field_' . $node->type . '_image';
      if (!empty(
$node->$key)) {
       
// Is 'embed' or 'value' the proper URL?  In my testing, they contain the same string.
       
$img_url = $node->{$key}[0]['embed'];
        if (empty(
$return['picture'])) {
         
$return['picture'] = $img_url;
        }
      }
?>

Or, get image URL with something like http://www.dave-cohen.com/comment/1000043#comment-1000043

As for the notice, I'm sure as that's in some other module. Is it caused by fb_stream???

#5