我正在尝试设置包含分享按钮的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>
答案 0 :(得分:0)
它在桌面和Android上工作正常,但这在iphone中不起作用。以下功能分享在iphone发布但没有显示Post发布(我认为响应在iphone 5中不起作用)。并更改所有参数
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript" charset="utf-8"></script>
<div id="fb-root"></div>
<script type="text/javascript" charset="utf-8">
FB.init({
appId: 'xxxxxxxxxxxxxx',
status: true,
cookie: true,
xfbml: true
});
function share_prompt() {
FB.ui( {
method: 'feed',
name: "fsdfsdf",
link: "abc.com/share-it/",
picture: "FacbookShareRed.jpg"
}, function( response ) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
} );
}
$(document).ready(function(){
$('button.share-btn').on( 'click', fb_share );
});
</script>
<a class="sc-facebook" value="Share with Facebook" onclick="share_prompt();">Share with Facebook</a>