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?

funerr
  • 7,212
  • 14
  • 81
  • 129

2 Answers2

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.

wzub
  • 324
  • 1
  • 6
  • Alternatively, you can use the [Like button](https://developers.facebook.com/docs/reference/plugins/like/) plugin – wzub Apr 20 '12 at 14:06
  • I need to implement it via js (@avist) – funerr Apr 20 '12 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](http://www.fbrell.com/fb.ui/feed). `Share this app` – wzub Apr 20 '12 at 14:18
  • Sorry, for some wired reason I didn't notice your code... thanks I have found that too! – funerr Apr 20 '12 at 14:42
  • But I can't use this code from different domains... what should I do? (http://stackoverflow.com/questions/10286881/facebook-using-code-from-different-domains) – funerr Apr 23 '12 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);
  }
Sachin Prasad
  • 5,365
  • 12
  • 54
  • 101