开发者

how to get user facebook logged in status

i am working on a small application in asp.net, c# in my website, which shows user is logged into facebook in the same browser. Which means in the browser if user open my website(in same browser if user is not logged into facebook) a popup should show that user is not loggedin. if the user logged into facebook then a popup should come in my website showing that loggedin after refresh of my page.

in a page refresh i just want to alert the login status of user... i had the xd_receiver.htm file in my root directory and

this script in header and

Untitled Page

<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() {
     开发者_JAVA百科          alert("After ensureInit");
               FB.Connect.ifUserConnected(onUserConnected, onUserNotConnected); 
            });
        };

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

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

this script in body....

But this code is not working..... how should i solve this...... thanks in advance


Try this for the html head part:

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

Then use this for the html > body part:

<div id="divstatus">
</div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜