使用Facebook Javascript SDK时出现错误FB not defined
FB.init({
appId: '{APP ID}',
status: true,
cookie: true,
xfbml: true
});
答案 0 :(得分:6)
两件事 -
我无法看到JS SDK已加载。
您必须在异步加载SDK后调用FB
函数,否则会抛出FB is not defined
所以,要解决它 -
// This will be triggered automatically after the SDK is loaded successfully
// write your FB fucntions inside this
window.fbAsyncInit = function() {
FB.init({
appId: '{app-id}',
status: true,
cookie: true,
xfbml: true
});
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
GetData();
} else {
Login();
}
});
};
// JS SDK - this will be loaded asynchronously
(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'));
function Login() {
...
...
}
function GetData() {
...
...
}
修改强>
我看到你要求获得许可email
但尚未使用它。使用实际的电子邮件(而不是facebook)与 - response.email