通过 JS SDK 的方法,你实际上可以知道用户是否登录了 Facebook FB.getLoginStatus()
(但它当然需要一个应用程序)。
not_authorized
即使不要求用户允许任何应用程序,Facebook 也会通过返回对上述方法的响应来 显示用户是否实际登录 Facebook 。
例子:
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>JS SDK Test</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID from the App Dashboard
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
FB.getLoginStatus(function(response) {
if( response.status == 'connected' || response.status == 'not_authorized' ) {
// user is logged-in to Facebook
}
});
};
// Load the SDK Asynchronously
(function(d, debug){
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" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));
</script>
</body>
</html>