I would like the option to be able to post to my fan page wall rather than my personal wall.

I think the best way would be to add a field to the content type settings where you can add the Facebook Page ID

If done that using

$form['fbconnect_settings']['onoff'] = array(
        '#type' => 'checkbox',
        '#title' => t('Allow this content type to publish to facebook'),
        '#default_value' => variable_get('fbconnect_' . $form['#node_type']->type . '_onoff', 0),
      );
  $form['fbconnect_settings']['pageid'] = array(
        '#type' => 'textfield',
        '#title' => t('Enter Facebook Page ID'),
'#default_value' => variable_get('fbconnect_' . $form['#node_type']->type . '_pageid', 0),
       );

so I can save the page id

I been a bit stuck now as what to do next.

Comments

vivianspencer’s picture

Did you make any progress on this? I'd like to see how you achieved this

marcus178’s picture

I've not really looked at any more, not really sure what to do to get it to post to the fan page wall.

vivianspencer’s picture

I've got it working, thought I'd post it here so you can try it yourself:

1. I created a module with the following code:

function YOURMODULE_facebook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
    if ($op == 'insert' || $op == 'update') {
        $fbuid  = fbconnect_get_fbuid();
        if (user_is_logged_in() && $fbuid) {
	    $message = t('Check out my latest post on !site...', array('!site' => variable_get('site_name', t('YOUR SITE'))));
            $attachment = array(
                'name' => $node->title,
                'href' => url('node/' . $node->nid, array('absolute' => TRUE)),
                'description' => $node->teaser,
            );
            $actions = array(array('text' => t('Read More'), 'href' => url('node/'.$node->nid, array('absolute' => TRUE))));
            $_SESSION['fbconnect_YOURMODULE'] = array();
            $_SESSION['fbconnect_YOURMODULE']['message'] = $message;
            $_SESSION['fbconnect_YOURMODULE']['attachment'] = json_encode($attachment);
            $_SESSION['fbconnect_YOURMODULE']['actions'] = json_encode($actions);
        }
    }
}

2. I added the followin to my template.php file although I'm sure this can go in the module also:

function YOURTHEME_preprocess_page(&$vars) {
    global $user;
    $fbuid  = fbconnect_get_fbuid();
    if (user_is_logged_in() && $fbuid) {
        if (!empty($_SESSION['fbconnect_YOURMODULE'])) {
            $api_key = variable_get('fbconnect_key', NULL);
            $profile_arr = json_encode(YOUR_FACEBOOK_PAGE_ID);
            drupal_add_js(
                'function publish_permission() {
                    FB_RequireFeatures(["Connect"], function() {
                        FB.init("'. $api_key .'", "xd_receiver.htm");
                        FB.ensureInit(function() {
                            FB.Connect.showPermissionDialog("publish_stream", publish, true, '. $profile_arr .');
                        });
                    });
                }
                function publish() {
                    FB.Connect.streamPublish("'. 
                        $_SESSION['fbconnect_YOURMODULE']['message'] .'", '. 
                        $_SESSION['fbconnect_YOURMODULE']['attachment'] .', '. 
                        $_SESSION['fbconnect_YOURMODULE']['actions'] .', '.
                        YOUR_FACEBOOK_PAGE_ID .');
                }', 'inline'
            );
            drupal_add_js('window.onload = publish_permission;', 'inline');
            $vars['scripts'] = drupal_get_js();
            unset($_SESSION['fbconnect_YOURMODULE']);
        }
    }
}

I know this isn't the perhaps the best way of doing this but it works for me

marcus178’s picture

I've given this a go by putting the first part in my custom.module and the other bit in my template.php by nothing seems to happen, I just get the normal popup which then posts to my profile wall.

Did you take any other steps to make this work?

vivianspencer’s picture

You need to make sure you set YOUR_FACEBOOK_PAGE_ID to your page id in the preprocess function

I also found that on some occasions the first permissions dialog that pops up only selects your profile, if you click the dropdown in the permissions dialog it should list any pages also related to your facebook account. I haven't found a way around this yet.

marcus178’s picture

Not really sure what's wrong just doesn't seem to do anything.

function phptemplate_preprocess_page(&$vars) {

    global $user;
    $fbuid  = fbconnect_get_fbuid();
    if (user_is_logged_in() && $fbuid) {
        if (!empty($_SESSION['fbconnect_custom'])) {
            $api_key = variable_get('fbconnect_key', NULL);
            $profile_arr = json_encode(xxxxxxxxxx);
            drupal_add_js(
                'function publish_permission() {
                    FB_RequireFeatures(["Connect"], function() {
                        FB.init("'. $api_key .'", "xd_receiver.htm");
                        FB.ensureInit(function() {
                            FB.Connect.showPermissionDialog("publish_stream", publish, true, '. $profile_arr .');
                        });
                    });
                }
                function publish() {
                    FB.Connect.streamPublish("'. 
                        $_SESSION['fbconnect_custom']['message'] .'", '. 
                        $_SESSION['fbconnect_custom']['attachment'] .', '. 
                        $_SESSION['fbconnect_custom']['actions'] .', '.
                        xxxxxxxxxx .');
                }', 'inline'
            );
            drupal_add_js('window.onload = publish_permission;', 'inline');
            $vars['scripts'] = drupal_get_js();
            unset($_SESSION['fbconnect_custom']);
        }
    }
}
/*Facebook Connect*/

function custom_facebook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
    if ($op == 'insert' || $op == 'update') {
        $fbuid  = fbconnect_get_fbuid();
        if (user_is_logged_in() && $fbuid) {
        $message = t('Check out my latest post on !site...', array('!site' => variable_get('site_name', t('Site name'))));
            $attachment = array(
                'name' => $node->title,
                'href' => url('node/' . $node->nid, array('absolute' => TRUE)),
                'description' => $node->teaser,
            );
            $actions = array(array('text' => t('Read More'), 'href' => url('node/'.$node->nid, array('absolute' => TRUE))));
            $_SESSION['fbconnect_custom'] = array();
            $_SESSION['fbconnect_custom']['message'] = $message;
            $_SESSION['fbconnect_custom']['attachment'] = json_encode($attachment);
            $_SESSION['fbconnect_custom']['actions'] = json_encode($actions);
        }
    }
}
vivianspencer’s picture

Code looks fine to me, have you logged in via facebook connect?

marcus178’s picture

Yes i'm logged in with Facebook, I do get the popup to post to facebook but it's just the normal one that posts to my profile.

vivianspencer’s picture

Ok, I'll put together a dev site later on and test your code

Are you sure you're using your page id?

marcus178’s picture

Should the post to Facebook option be ticked in the Content type?

Still not got this to work, the correct dialogue box did popup once after asking permission but haven't been able to replicate that since.

marcus178’s picture

Finally got it working, and you need to make sure posting to wall is not ticket for the content type.

The following code is in a custom module, just replace the xxxxxxxxxx with your page id. I have also include a image field in the attachment but that will need changing depending on your setup.

function fbfanpage_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
    if ($op == 'insert' || $op == 'update') {
        $fbuid  = fbconnect_get_fbuid();
        if (user_is_logged_in() && $fbuid) {
        $message = t('Check out my latest post on !site...', array('!site' => variable_get('site_name', t('YOUR SITE'))));
            $attachment = array(
                'name' => $node->title,
                'href' => url('node/' . $node->nid, array('absolute' => TRUE)),
                'description' => $node->teaser,
				'media' => array(array('type' => 'image', 'src' => url(($node->field_event_image[0]['filepath']), array('absolute' => TRUE)), 'href' => url('node/' . $node->nid, array('absolute' => TRUE)))),          
            );
            $actions = array(array('text' => t('Read More'), 'href' => url('node/'.$node->nid, array('absolute' => TRUE))));
            $_SESSION['fbconnect_fbfanpage'] = array();
            $_SESSION['fbconnect_fbfanpage']['message'] = $message;
            $_SESSION['fbconnect_fbfanpage']['attachment'] = json_encode($attachment);
            $_SESSION['fbconnect_fbfanpage']['actions'] = json_encode($actions);
        }
    }
}

function fbfanpage_preprocess_page(&$vars) {
    global $user;
    $fbuid  = fbconnect_get_fbuid();
    if (user_is_logged_in() && $fbuid) {
        if (!empty($_SESSION['fbconnect_fbfanpage'])) {
            $api_key = variable_get('fbconnect_key', NULL);
            $profile_arr = json_encode('xxxxxxxxxx');
            drupal_add_js(
                'function publish_permission() {
                    FB_RequireFeatures(["Connect"], function() {
                        FB.init("'. $api_key .'", "xd_receiver.htm");
                        FB.ensureInit(function() {
                            FB.Connect.showPermissionDialog("publish_stream", publish, true, '. $profile_arr .');
                        });
                    });
                }
                function publish() {
                    FB.Connect.streamPublish("'. 
                        $_SESSION['fbconnect_fbfanpage']['message'] .'", '. 
                        $_SESSION['fbconnect_fbfanpage']['attachment'] .', '. 
                        $_SESSION['fbconnect_fbfanpage']['actions'] .', '.
                        xxxxxxxxxx .');
                }', 'inline'
            );
            drupal_add_js('window.onload = publish_permission;', 'inline');
            $vars['scripts'] = drupal_get_js();
            unset($_SESSION['fbconnect_fbfanpage']);
        }
    }
	}
eranback’s picture

Component: Code » Documentation
Category: feature » support

Hi

Posting to a fan page or any other page would be easier to do using the "secret" email facebook suplly
also called

your_secret_email@m.facebook.com

the email uses to post photos / videos but also applicable for pure text
more info here - http://www.facebook.com/pages/edit/?id=103995946314195#!/help/?topic=pag...

bottom line: it would be easier to send an email than use fb-dff-connect-javascript-more
hope that's helps ...

as for me, I would like to update the user's feed/wall so I dont have the user's secret email (each facebook user have one) so it is little bit more complicated

e-fee’s picture

@marcus: tried your piece of code, put it into a module.

First I get an error message like this:

API Error Code: 114
API Error Description: Invalid user id list
Error Message: must be a valid ID string (e.g., "123")

Seems to refer to

public function application_getPublicInfo($application_id=null,
265 	                                            $application_api_key=null,
266 	                                            $application_canvas_name=null) {
267 	    return $this->call_method('facebook.application.getPublicInfo',
268 	        array('application_id' => $application_id,
269 	              'application_api_key' => $application_api_key,
270 	              'application_canvas_name' => $application_canvas_name));
271 	  }

in facebookapi_php5_restlib.php but I don't know what to do with that!

Seems to be treated as a posting to a friend's wall (actually it's supposed to be posting to my page which is connected with my app, both under the account which is connected), again an error message that it can't be posted.
After that it wants to post to my own wall and this works fine.

agira’s picture

Issue tags: +application wall

Same I want to do for my facebook application wall, my website which use fbconnect is registered as facebook application, then any new nodes content from that my website i want to see not on my personal wall - but on application wall, searching now for solution.

butler360’s picture

Subscribing.

benone’s picture

subscribe

  • vectoroc committed a370514 on
    #888756 : added type attribute of script tag #907958 : updated FAQ #...