簡體   English   中英

Facebook javascript SDK沒有響應

[英]Facebook javascript SDK not responding

嗨,我有我嘗試使用Facebook JavaScript SDk開發的代碼。 當我在Firebug中對其進行測試時,該代碼可以正常工作,但是在我對其進行測試時和網頁中卻沒有響應。 我已經為該特定網站設置了應用程序,但沒有響應

<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。

您的自調用函數是錯誤的-關閉括號的排列不正確,因此不會被調用。 更改為:

(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);
})();

當我在未向Facebook注冊的域上測試頁面時,通常會遇到這些問題。 您要測試的URL與Facebook中的域匹配嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM