0

So I am using facebooker2 plugin to do facebook connect. I was able to extract information about a user, but here's what I have been struggling with...

I am not sure how to post something onto my wall or my friends' walls.. I know that in facebooker, you can call the method publish_to and it will do the job. But it seems like facebooker2 is a little bit less documented as I looked all over google..

I was wondering if any expert who could help on this one?

Thanks alot

Jacky
  • 49
  • 1
  • 5

1 Answers1

2

if Your using facebooker2 which integrates Facebook Connect You'll probably need to do it on the client side. if I understand correctly facebooker2 does not provide any server side API.

thus load the JavaScript SDK (should be loaded if You've succesfully connected) and go ahead posting statuses with the integrated Facebook UI :

FB.ui({
    method: 'stream.publish',
    attachment: {
      name: 'JSSDK',
      caption: 'The Facebook JavaScript SDK',
      description: (
        'A small JavaScript library that allows you to harness ' +
        'the power of Facebook, bringing the user\'s identity, ' +
        'social graph and distribution power to your site.'
      )
    }
  },
  function(response) {
    if (response && response.post_id) {
      alert('Post was published.');
    } else {
      alert('Post was not published.');
    }
  }
);

FB.ui supports the following dialogs :

  • friends.add
  • stream.publish
  • stream.share
  • fbm.dialog
  • bookmark.add
  • profile.addtab

if You wan't to publish a status update to the feed directly without the fancy UI use the FB.api function :

var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post ID: ' + response.id);
  }
});

UPDATE:

actually You could do all this server side - i did not notice Mongli at first - integrates FB Open Graph API (facebooker2 gem depends on it), sample controller action :

def create
  note = current_user.sent_notes.create!(params[:note])
  flash[:notice] = "Note sent to #{note.recipient.email}"
  if current_facebook_user
    current_facebook_user.fetch
    current_facebook_user.feed_create(
      Mogli::Post.new(:name => "#{current_facebook_user.name} sent a note using notes!",
                      :link=>note_url(note),
                      :description=>truncate(note.body,:length=>100)))
  end
  redirect_to notes_path
end

@see Mogli at https://github.com/mmangino/mogli

@see facebooker2 example at https://github.com/mmangino/facebooker2_fb_connect_example

kares
  • 7,076
  • 1
  • 28
  • 38
  • Thank you very much for your response. It does exactly what I was hoping for. I have another question, not sure if you could kindly help as well. I am having this race condition. When I login/logout directly from my app, I have no problem. But as soon as I login from my app and logout using facebook, I get this error "Error validating access token." I think this is because that my app still think that I am logged in even though I already logged out from facebook. I was wondering if you have any insight on how to fix this problem? – Jacky Dec 08 '10 at 21:31
  • @Jacky well I'm affraid I can't help You with that without seeing any of Your code. it sounds to me like You should have a before filter in Your controller that validates the access token and if it's invalid re-initializes connect (or redirects to facebook login - whatever You're expecting to happen in such case) ... maybe You should post another question with Your code and expected behavior and someone will hopefully help You. – kares Dec 10 '10 at 14:56