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('' + '?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.
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.
- It means that Facebook can not scrape your site – WizKid Commented Sep 24, 2014 at 18:35
- Ok. What does Facebook not being able to scrape my site mean? – davidpauljunior Commented Sep 24, 2014 at 19:49
- Facebook need to be able to fetch the page you want to share to be able to get the information about it – WizKid Commented Sep 24, 2014 at 20:37
- 1 Sorry I may not have made this clear, but the whole point of the question is that I want to be able to test the Facebook Share Dialog in my local environment. – davidpauljunior Commented Sep 24, 2014 at 21:14
- 6 WizKid, your answers didn't help anyone. – Miguel Stevens Commented Oct 7, 2014 at 17:57
3 Answers
Reset to default 8Since 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.
What @WizKid is trying to say is that Facebook is looking for some meta tags on your page (e.g. <meta property="og:title" content="My awesome site" />
, so that it can structure the content of your share... but isn't finding them. Your current share may work on production, but won't on localhost. You can test to see what facebook is looking for with their url debugger: https://developers.facebook.com/tools/debug/
The old URL-parameter-based sharing works with localhost (if you've added it as a site URL and app domain) because all facebook had to do in that instance was parse the query parameters of your share string.
To test facebook share debugger on localhost we can create a tunnel.
Follow the below steps source: facebook share debugger on localhost