【发布时间】:2015-03-20 22:37:49
【问题描述】:
我正在尝试设置一个包含共享按钮的 Facebook 页面标签应用程序。它可以很好地显示共享对话框,但没有调用回调。如果我将 FB.ui 函数放在 window.fbAsyncInit 函数中,那么回调会很好。但是,这样做会使共享窗口出现在页面加载时。我想让它显示在单击按钮上。我尝试仅在单击按钮后调用 window.fbAsyncInit 函数,但这也不起作用。这是我页面的完整 HTML:
<html>
<head>
</head>
<body style="background-color:#9ec64e;">
<div id="fb-root"></div>
<table style="width:100%">
<tr><td>
<br>
<h1>Press button to share</h1>
</td>
<td>
<p id="enterButton"><a href='' onclick="showShare();"><img src='share_btn.png' style='width:200px;'></a></p>
</td>
</tr>
</table>
<script>
function showShare() {
console.log("showShare");
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs', // name of the product or content you want to share
link: 'https://developers.facebook.com/docs/reference/dialogs/', // link back to the product or content you are sharing
picture: 'http://fbrell.com/f8.jpg', // path to an image you would like to share with this content
caption: 'Reference Documentation', // caption
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.' // description of your product or content
},
function(response) {
console.log("finished");
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'XXXXXXXXX',
xfbml : true,
version : 'v2.2'
});
// Additional initialization code such as adding Event Listeners goes here
};
(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'));
</script>
</body>
</html>
【问题讨论】:
-
我不明白为什么这不起作用。浏览器控制台中的任何错误?你能展示一个页面标签的实例吗?
-
好的,你需要先去阅读Platform Policies——不允许让别人分享来参加比赛。
-
谢谢 - 没有意识到这一点。现在好像很多人都这样做了,但我现在把它拿下来了。仍然没有回答为什么它不起作用的问题。
标签: javascript facebook