2013-04-15 109 views
1

我一直在使用以下JavaScript通過Facebook登錄我的用戶。它工作了幾個星期,但突然停止工作。Facebook登錄(JavaScript)突然停止工作

當我點擊登錄按鈕時,常規的Facebook連接窗口打開,但是當我登錄會話似乎仍然未設置。

<div id="fb-root"></div> 
<script type="text/javascript"> 
window.fbAsyncInit = function() { 
FB.init({appId: 'MY_APP_ID',cookie: true,xfbml: true,channelUrl: 'http://MYURL.com/channel.php',oauth: 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);}()); 

function CallAfterLogin(){ 
     FB.login(function(response) {  
     if (response.status === "connected") 
     { 
      LodingAnimate(); //Animate login 
      FB.api('/me', function(data) { 

       window.location = 'http://MYURL.com/<?=$_SESSION['lang']; ?>'; 

      }); 
     } 
    }); 
} 

</script> 

守則channel.php

<?php 
$cache_expire = 60*60*24*365; 
header("Pragma: public"); 
header("Cache-Control: max-age=".$cache_expire); 
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$cache_expire) . ' GMT'); 
?><script src="//connect.facebook.net/en_US/all.js"></script> 
+0

使用什麼'<?php = $ _ SESSION ['lang']; ?>'做? (添加'php')。 –

+0

好吧,我懷疑這與錯誤有什麼關係,但它包含用戶選擇的語言。 –

+0

你有沒有試過用螢火蟲控制檯或谷歌Chrome開發者工具調試它? –

回答

2

這是你應如何處理用戶身份:

<div id="fb-root"></div> 
<script type="text/javascript"> 
window.fbAsyncInit = function() { 
      FB.init({ 
       appId  : 'MY_APP_ID', // App ID 
       channelUrl : 'http://MYURL.com/channel.php', // Channel File 
       status  : true, // check login status 
       cookie  : true, // enable cookies to allow the server to access the session 
       xfbml  : true // parse XFBML 
      }); 

      // Additional initialization code here 
      FB.getLoginStatus(function (response) { 
      if (response.status === 'connected') { 
       FB.api('/me', function(data) { 

       window.location = 'http://MYURL.com/<?=$_SESSION['lang']; ?>'; 

       }); 
      } else if (response.status === 'not_authorized') { 
       //you must ask permissions to the user 
      } else { 
       //user is not logged, just change the scope for the ones you want or remove 
       //it if you don't need any additional permissions 
       FB.login(function(response) { }, {scope:'email,user_likes'}); 
      } 
     }); 
     }; 

     // Load the SDK Asynchronously 
     (function(d){ 
      var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
      if (d.getElementById(id)) {return;} 
      js = d.createElement('script'); js.id = id; js.async = true; 
      js.src = "//connect.facebook.net/pt_PT/all.js"; 
      ref.parentNode.insertBefore(js, ref); 
     }(document)); 
</script> 

編輯

這是當前你的頁面代碼

<body> 

<div id="fb-root" class=" fb_reset"><div style="position: absolute; top: -10000px; height: 0px; width: 0px;"><div><iframe name="fb_xdm_frame_http" frameborder="0" allowtransparency="true" scrolling="no" id="fb_xdm_frame_http" aria-hidden="true" title="Facebook Cross Domain Communication Frame" tab-index="-1" style="border: none;" src="http://static.ak.facebook.com/connect/xd_arbiter.php?version=21#channel=f2c633f99&amp;origin=http%3A%2F%2Ftictam.com&amp;channel_path=%2Fse%3Ffb_xd_fragment%23xd_sig%3Dfd496acc4%26"></iframe><iframe name="fb_xdm_frame_https" frameborder="0" allowtransparency="true" scrolling="no" id="fb_xdm_frame_https" aria-hidden="true" title="Facebook Cross Domain Communication Frame" tab-index="-1" style="border: none;" src="https://s-static.ak.facebook.com/connect/xd_arbiter.php?version=21#channel=f2c633f99&amp;origin=http%3A%2F%2Ftictam.com&amp;channel_path=%2Fse%3Ffb_xd_fragment%23xd_sig%3Dfd496acc4%26"></iframe></div></div><div style="position: absolute; top: -10000px; height: 0px; width: 0px;"><div><iframe name="f68921bbc" frameborder="0" allowtransparency="true" scrolling="no" style="display: none;" src="https://www.facebook.com/dialog/oauth?client_id=APP_ID&amp;response_type=token%2Csigned_request%2Ccode&amp;display=none&amp;domain=tictam.com&amp;origin=1&amp;redirect_uri=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D21%23cb%3Df1f63150cc%26origin%3Dhttp%253A%252F%252Ftictam.com%252Ff2c633f99%26domain%3Dtictam.com%26relation%3Dparent&amp;sdk=joey"></iframe></div></div></div> 
<script>(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/sv_SE/all.js#xfbml=1&appId=APP_ID"; 
    fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk'));</script> 




<div id="intro_form" style="margin-top: -2px; top: 0px; position: fixed; z-index: 100; min-height: 50px;"> 

    <a href="/se"><img src="/logo3.png" style="margin-bottom: -19px;" border="0"></a> 

<form method="post" action="/se/find" style="margin: 0px; padding: 0px; clear: none; display: inline;" id="search_form"> 
    <input type="text" name="what" placeholder="Vad?" value=""> <input type="text" name="where" placeholder="Var?" value=""> <input type="submit" name="search" id="intro_submit" value="Sök!" style="width: 224px !important; cursor: pointer; margin-right: 4px;"> 
    </form> 


    <form method="post" action="/se/find" style="margin: 0px; padding: 0px; clear: none; display: none; margin-top: 20px;" id="search_form_2"> 
    <input type="text" name="what" placeholder="Vad?" value=""> <input type="text" name="where" placeholder="Var?" value=""> <input type="submit" name="search" id="intro_submit" value="Sök!" style="width: 224px !important; cursor: pointer; margin-right: 4px;"> 
    </form> 

    <img src="/search-icon.png" width="35" height="35" id="search_icon" style="display: none; margin-top: 11px; margin-right: 11px; float: right; clear: both;"> 


    </div> 


    <script type="text/javascript"> 

    $(document).ready(function() 
    { 
     if ($(window).width() < 900) 
     { 
      $("#search_form").hide(); 
      $("#search_icon").show(); 
     } 
    }); 

    $("#search_icon").click(function() 
    { 
     $("#search_form_2").toggle("slow"); 
    }); 

    </script> 

    <div style="height: 50px;"></div> 

<div id="fb-root"></div> 
<script type="text/javascript"> 
window.fbAsyncInit = function() { 
      FB.init({ 
       appId  : '360183997416092', // App ID 
       channelUrl : 'http://tictam.com/channel.php', // Channel File 
       status  : true, // check login status 
       cookie  : true, // enable cookies to allow the server to access the session 
       xfbml  : true // parse XFBML 
      }); 

      // Additional initialization code here 
      FB.getLoginStatus(function (response) { 
      if (response.status === 'connected') { 
       FB.api('/me', function(data) { 

       window.location = 'http://tictam.com/se'; 

       }); 
      } else if (response.status === 'not_authorized') { 
       //you must ask permissions to the user 
      } else { 
       //user is not logged, just change the scope for the ones you want or remove 
       //it if you don't need any additional permissions 
       FB.login(function(response) { }, {scope:'email, user_work_history, user_education_history'}); 
      } 
     }); 
     }; 

     // Load the SDK Asynchronously 
     (function(d){ 
      var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
      if (d.getElementById(id)) {return;} 
      js = d.createElement('script'); js.id = id; js.async = true; 
      js.src = "//connect.facebook.net/pt_PT/all.js"; 
      ref.parentNode.insertBefore(js, ref); 
     }(document)); 
</script> 

正如你可以看到你旁邊正在裝載AA的JavaScript SDK,然後在底部你再次加載使用我的代碼<body>標籤,去掉第一個和下一個移動我的代碼到<body>標籤

+0

將代碼更改爲這個,並且它仍然不起作用 –

+0

控制檯上的任何錯誤? –

+0

現在它告訴我應用程序ID是不正確的,它是(相信我,我檢查過) –