Facebook JS Integration Error
I have the following code right开发者_如何学编程 below the body tag of my application
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: '136904373......', status: true, cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
FB.getLoginStatus(function(response) {
if (response.session) {
alert('Logged In');
} else {
alert('Not Logged In');
}
});
</script>
I'm currently getting the following error "FB not defined for FB.getLoginStatus(function(response) which makes me believe that the FB.init is not being loaded correctly. Anyone have any ideas (I've obscured the last 6 digits of my app idea on purpose)
Thanks
The getLoginStatus may not complete if the init call is missing valid parameters, such as the appId, or if the domain on which you've loaded the page does not match the site domain configured for the application.
I suggest adding your methods to the init function to make sure that they run after it's been initialized. It's possible that your code is being executed before the javascript file is finished loading since you're loading it asynchronously.
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: '136904373......', status: true, cookie: true,
xfbml: true});
FB.getLoginStatus(function(response) {
if (response.session) {
alert('Logged In');
} else {
alert('Not Logged In');
}
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
精彩评论