简体   繁体   English

Facebook javascript SDK没有响应

[英]Facebook javascript SDK not responding

Hi I have this code which i was trying to develop using Facebook JavaScript SDk. 嗨,我有我尝试使用Facebook JavaScript SDk开发的代码。 The code works fine when i test it in Firebug but doesn't respond when i test it and a webpage. 当我在Firebug中对其进行测试时,该代码可以正常工作,但是在我对其进行测试时和网页中却没有响应。 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. 当我在未向Facebook注册的域上测试页面时,通常会遇到这些问题。 Does the URL that you are testing on match the domain in Facebook? 您要测试的URL与Facebook中的域匹配吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM