2011-03-10 36 views
0

我正在asp.net中的一個小應用程序,在我的網站的c#,它顯示用戶登錄到Facebook在同一瀏覽器。這意味着在瀏覽器中,如果用戶打開我的網站(如果用戶未登錄Facebook,則在同一瀏覽器中)彈出窗口應顯示用戶未登錄。如果用戶登錄Facebook,那麼一個彈出窗口應該在我的網站上顯示刷新我的頁面後登錄。如何讓用戶的Facebook登錄狀態

在頁面刷新我只是想提醒用戶的登錄狀態

... 我在我的根目錄和文件xd_receiver.htm

這個腳本在頭和

無題第

<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" 
    type="text/javascript"></script> 

<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js#appId=142899075774321&amp;xfbml=1"></script> 

<script type='text/javascript' language='javascript'> 
window.onload = function() { 
      FB.init('142899075774321', 'xd_receiver.htm'); 
      alert("Before ensureInit"); 
      FB.ensureInit(function() { 
       alert("After ensureInit"); 
       FB.Connect.ifUserConnected(onUserConnected, onUserNotConnected); 
      }); 
     }; 

     function onUserConnected() { 
      alert('connected!'); 
      window.location.reload(); 
     } 

     function onUserNotConnected() { 
      alert('not connected'); 
     } 
</script> 

這個腳本在身體....

但這種代碼是不能工作..... 我應該如何解決這個...... 由於事先

回答

0

嘗試本作的html頭部:

<title>Facebook Status</title> 
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US" 
    type="text/javascript"> 
</script>  
<script type="text/javascript">     
     var api_key = 'Your app id'; 
     var channel_path = 'xd_receiver.htm';   
     //alert(document.referrer); 
     FB_RequireFeatures(["XFBML"], function() { 
      // Create an ApiClient object, passing app's API key and 
      // a site relative URL to xd_receiver.htm 
      FB.Facebook.init(api_key, channel_path); 
      FB.Connect.get_status().waitUntilReady(function(status) { 
       switch(status) { 
       case FB.ConnectState.connected: 
       document.getElementById("divstatus").innerHTML ="LOGGED IN AUTHORIZED";      
       break; 
       case FB.ConnectState.appNotAuthorized: 
       document.getElementById("divstatus").innerHTML ="LOGGED IN NOT AUTHORIZED";      
       break; 
       case FB.ConnectState.userNotLoggedIn: 
       document.getElementById("divstatus").innerHTML ="NOT LOGGED IN";      
       break; 
       } 
      }); 
     });  
</script>  

然後用這個爲html > body部分:

<div id="divstatus"> 
</div> 
相關問題