2012-06-13 44 views
0

我非常新的計算器和編碼,但我會盡我所能,使這個問題清晰和簡單越好:Facebook的像和註銷

我希望創建一個網頁,在那裏我有一個Facebook像按鈕和註銷按鈕,將簽署用戶的Facebook帳戶...所以用戶可以在Facebook Like,輸入登錄信息,然後註銷。這裏的腳本我到目前爲止,但我刷新爲了註銷工作,並直接回到主頁面。非常感謝您的幫助:

互動環節:http://jsfiddle.net/nrdnx/11/

代碼:

<html> 
    <head> 
     <title>My Great Web page</title> 
    </head> 
    <body> 
<div id="fb-root"></div> 

<script> 
window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : '271358172932770', // App ID 
     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 
    getStatus(); 
    }; 

    // 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/en_US/all.js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document)); 


</script> 



</script> 

     <iframe src="http://www.facebook.com/plugins/like.php?href=www.facebook.com/orangeleaflawrence" 
     scrolling="no" frameborder="0" 
     style="border:none; width:450px; height:80px"></iframe> 

<a href="javascript:void();" onclick="getStatus()">Get Status</a> 


<div id="logout"><a href="logout.html">Logout of Facebook</a></div> 


<script> 

FB.Event.subscribe('auth.authResponseChange', function(response) { 
    alert('The status of the session is: ' + response.status); 
}); 




function getStatus(){ 

FB.getLoginStatus(function (response) { 
    alert(response.status); 
    if (response.status === 'connected') { 

     document.getElementById('logout').style.display=''; 
    // the user is logged in and has authenticated your 
    // app, and response.authResponse supplies 
    // the user's ID, a valid access token, a signed 
    // request, and the time the access token 
    // and signed request each expire 
    } else if (response.status === 'not_authorized') { 
    document.getElementById('logout').style.display='none'; 
    // the user is logged in to Facebook, 
    // but has not authenticated your app 
    } else { 

    // the user isn't logged in to Facebook. 
     document.getElementById('logout').style.display='none'; 
    } 
} 
); 

} 






</script> 


</body> 
</html> 

回答