Hi I have this code which i was trying to develop using Facebook JavaScript SDk. The code works fine when i test it in Firebug but doesn't respond when i test it and a webpage. I have setup the application for that particular website but it doesn't respond
<div id="fb-root"></div>
<script type="text/javascript">
(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>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXXX',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
function updateButton(response) {
var button = document.getElementById('auth_button');
button.onclick = function() {
FB.login(function(response) {
button.innerHTML = 'Logout';
});
}
if (response.status === 'connected') {
button.innerHTML = 'Logout';
button.onclick = function() {
FB.logout(function(response) {
alert('FB.logout');
});
};
} else {
button.innerHTML = 'Login';
button.onclick = function() {
FB.login(function(response) {
alert('FB.login callback');
if (response.status === 'connected') {
alert('User is logged in');
} else {
alert('User is logged out');
}
});
};
}
}
// run it once with the current status and also whenever the status changes
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
</script>
尝试同步加载JS SDK。
Your self-calling function is wrong - the closing parens are lined up incorrectly and so it isn't going to be called. Change it to:
(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);
})();
I usually get these problems when I am testing the page on a domain that wasn't registered with Facebook. Does the URL that you are testing on match the domain in Facebook?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.