我无法弄清楚如何成功加载和执行 fb.ui 函数。我看到您需要有一个 facebook 应用程序 ID,所以我创建了一个空白应用程序并将其放在 appId 部分。这是我当前的代码:
加载和初始化:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '1404387053111932',
channelUrl : 'channel.htm;',
status : true,
xfbml : true
});
};
(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/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
FB.ui 脚本:
<script>
FB.ui(
{
method: 'feed',
name: 'The Facebook SDK for Javascript',
caption: 'Bringing Facebook to the desktop and mobile web',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
link: 'https://developers.facebook.com/docs/reference/javascript/',
picture: 'http://www.fbrell.com/public/f8.jpg'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
</script>
通道.html 文件:
<html>
<head>
<script src="http://connect.facebook.net/en_US/all.js"></script>
</head>
<body>
</body>
</html>
我想我的主要问题是如何调用此代码以在点击时执行?我会在 fb.ui {} 周围包装一个函数吗?