我正在尝试使用我根据新文档编写的以下代码来显示“发布到提要”对话框(https://developers.facebook.com/docs/javascript/reference/FB.ui),但我得到了出现以下错误“ ReferenceError:FB 未定义”
我使用的代码是我能想到的最简单的代码:
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxx',
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 = "http://connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
FB.ui({
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
});
有任何想法吗?
编辑 1
如果我想在用户单击链接时打开对话框,我将使用 jquery click 事件
$(".userActions a.facebook").click(function() {
FB.ui({
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
});
});
或者将 FB.ui 放在一个接受参数并调用此函数的函数中,例如
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxx',
status : true,
xfbml : true
});
// Code in here will run once FB has been initialised
function FB_post_feed(method,name,link,picture,caption,description){
FB.ui({
method: method,
name: name,
link: link,
picture: picture,
caption: caption,
description: description
});
}
};
(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 = "http://connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
在 HTML 中的某处
$(".userActions a.facebook").click(function() {
FB_post_feed('feed','Facebook Dialogs','https://developers.facebook.com/docs/dialogs/','http://fbrell.com/f8.jpg','Reference Documentation','Dialogs provide a simple, consistent interface for applications to interface with users.')
}