1

I have read that the Facebook sharer is deprecated, So I wanted to know how can I create a share button in my widget that will work from any domain (not just the app domain), via the js SDK (Preferably).

For example:
I have my app registered on myserver.com
And someone downloaded my widget on hisservers.com, I want the share to work from there and post to his wall.

How can I do so?

2 Answers 2

1

You can use the FB.ui Feed dialog to prompt the user to publish a story on their feed, and specify your link in the function. Like so

function postLink() {
    var obj = {
      method: 'feed',
      link: 'http://myserver.com',
      picture: 'a_picture',
      name: 'My Server',
      description: 'Sharing MyServer from HisServer.'
    };

    function callback(response) {
      console.log(response['post_id']);
    }

    FB.ui(obj, callback);
  }

Of course you'll have to also include the proper initialization for the JS SDK.

5
  • Alternatively, you can use the Like button plugin
    – wzub
    Apr 20, 2012 at 14:06
  • I need to implement it via js (@avist)
    – funerr
    Apr 20, 2012 at 14:13
  • That is JS! You can call the postLink() function, after initializing the JS SDK (see link in answer), and it will open a popup. Example. <a href="#share" onclick="postLink(); return false();">Share this app</a>
    – wzub
    Apr 20, 2012 at 14:18
  • Sorry, for some wired reason I didn't notice your code... thanks I have found that too!
    – funerr
    Apr 20, 2012 at 14:42
  • But I can't use this code from different domains... what should I do? (stackoverflow.com/questions/10286881/…)
    – funerr
    Apr 23, 2012 at 20:11
1
function postLink() {
    var obj = {
      method: 'feed',
      link: 'http://myserver.com',
      picture: 'a_picture',
      name: 'My Server',
      description: 'Sharing MyServer from HisServer.'
    };

    function callback(response) {
      console.log(response['post_id']);
    }

    FB.ui(obj, callback);
  }
1
  • Format your code before posting. Also an explanation on the code would help.
    – Unni Kris
    Nov 14, 2012 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.