Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Facebook Share Dialog with localhost - "Unable to resolve object at URL http://localhost"

I'm trying to use the current (at date of asking this question) Facebook Share Dialog using just the URL (not the SDK).

My JS looks like this:

openFacebookPopup : function (url) {
        this.openSharerWindow('https://www.facebook.com/dialog/share' + '?app_id=145634995501895' + '&display=popup' + '&href=http%3A%2F%2Flocalhost' + '&redirect_uri=http%3A%2F%2Flocalhost');
        return false;
}

The error I'm getting is:

Could not resolve object at URL http://localhost/.

What does that mean and how do I go about trying to resolve it? I should note that this JS does work without problems using the old 'sharer.php' url for facebook.

I've got http://localhost added into my app.

like image 355
davidpauljunior Avatar asked Sep 24 '14 16:09

davidpauljunior


1 Answers

Since FB can't access to your localhost to feed the popup, you have to feed it yourself.

First, add the Facebook's Javascript SDK on every pages you need it :

  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'your-app-id',
      xfbml      : true,
      version    : 'v2.3'
    });
  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));

Then, bind this function on whatever trigger you want, a click event for example :

$('#fb-share-button').click(function() {
    FB.ui({
          method: 'feed',
          link: "The link you want to share", 
          picture: 'The picture url',
          name: "The name who will be displayed on the post",
          description: "The description who will be displayed"
        }, function(response){
            console.log(response);
        }
    );
});

I console.log the response but in this block you can do what you want. Catch the response to see if the post has been well shared for example.

like image 197
looggi Avatar answered Sep 22 '22 04:09

looggi