使用localhost测试Facebook共享对话框 - “无法在URL http:// localhost上解析对象” [英] Testing Facebook Share Dialog with localhost - "Unable to resolve object at URL http://localhost"
问题描述
我正在尝试使用当前(在提出此问题的日期)Facebook Share Dialog仅使用URL(而不是SDK)。
I'm trying to use the current (at date of asking this question) Facebook Share Dialog using just the URL (not the SDK).
我的JS看起来像这样:
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;
}
我得到的错误是:
无法在URL
http:// localhost /
中解析对象。
这是什么意思,我该如何解决呢?
我应该注意到,这个JS在没有问题的情况下使用旧的sharer.phpurl进行Facebook的工作。
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.
我有 http:// localhost
添加到我的应用程序。
I've got http://localhost
added into my app.
推荐答案
由于FB无法访问您的本地主机可以弹出弹出窗口,您必须自己提供。
Since FB can't access to your localhost to feed the popup, you have to feed it yourself.
首先,在您需要的每个页面上添加Facebook的Javascript SDK:
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);
}
);
});
我的console.log的响应,但在这个块,你可以做你想要的。抓住回应,看看帖子是否已经很好地分享了。
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.
这篇关于使用localhost测试Facebook共享对话框 - “无法在URL http:// localhost上解析对象”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!