Javascript FB.getLoginStatus response.status是否始终连接?
我正在使用apache cordova/phonegap开发一个应用程序。我的问题是,当用户从本机facebook应用程序注销facebook时,在我的应用程序中,当我调用Javascript FB.getLoginStatus response.status是否始终连接?,javascript,html,facebook,cordova,facebook-login,Javascript,Html,Facebook,Cordova,Facebook Login,我正在使用apache cordova/phonegap开发一个应用程序。我的问题是,当用户从本机facebook应用程序注销facebook时,在我的应用程序中,当我调用FB.getLoginStatus时,状态总是connected。我做错了什么?如何检测用户是否已从facebook本机应用注销 <?xml version="1.0" encoding="UTF-8" ?> <!<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML
FB.getLoginStatus
时,状态总是connected
。我做错了什么?如何检测用户是否已从facebook本机应用注销
<?xml version="1.0" encoding="UTF-8" ?>
<!<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>yourFREEtree</title>
<meta http-equiv="content-type" content="application/xhtml+xml" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" media="all and (orientation:portrait)" href="style.css">
</head>
<body>
<div id="data">loading ...</div>
<div id="fb-root"></div>
<!-- cordova -->
<script src="cordova.js"></script>
<!-- cordova facebook plugin -->
<script src="cdv-plugin-fb-connect.js"></script>
<!-- facebook js sdk -->
<script src="facebook-js-sdk.js"></script>
<script>
<!-- These are the notifications that are displayed to the user through pop-ups if the above JS files does not exist in the same directory-->
if ((typeof cordova == 'undefined') && (typeof Cordova == 'undefined')) alert('Cordova variable does not exist. Check that you have included cordova.js correctly');
if (typeof CDV == 'undefined') alert('CDV variable does not exist. Check that you have included cdv-plugin-fb-connect.js correctly');
if (typeof FB == 'undefined') alert('FB variable does not exist. Check that you have included the Facebook JS SDK file.');
FB.Event.subscribe('auth.login', function(response) {
});
FB.Event.subscribe('auth.logout', function(response) {
//alert('auth.logout '+response.status);
});
FB.Event.subscribe('auth.sessionChange', function(response) {
//alert('auth.sessionChange '+response.status);
});
FB.Event.subscribe('auth.statusChange', function(response) {
FB.getLoginStatus(function(response) {
// this will be called when the roundtrip to Facebook has completed
alert(response.status);
//alert(response.authResponse.accessToken);
}, true);
});
document.addEventListener('deviceready', function() {
try {
//alert('Device is ready! Make sure you set your app_id below this alert.');
FB.init({ appId: "{MYAPPID HERE}", nativeInterface: CDV.FB, useCachedDialogs: false });
document.getElementById('data').innerHTML = "";
} catch (e) {
alert(e);
}
}, false);
</script>
yourFREEtree
加载。。。
如果((typeof cordova=='undefined')&(typeof cordova=='undefined'))警报('cordova变量不存在。请检查是否正确包含cordova.js');
if(typeof CDV=='undefined')警报('CDV变量不存在。请检查您是否正确包含了CDV-plugin-fb-connect.js');
如果(typeof FB=='undefined')警报('FB变量不存在。请检查是否包含Facebook JS SDK文件');
FB.Event.subscribe('auth.login',函数(响应){
});
FB.Event.subscribe('auth.logout',函数(响应){
//警报('auth.logout'+response.status);
});
FB.Event.subscribe('auth.sessionChange',函数(响应){
//警报('auth.sessionChange'+response.status);
});
FB.Event.subscribe('auth.statusChange',函数(响应){
FB.getLoginStatus(函数(响应){
//这将在往返Facebook完成后调用
警报(响应状态);
//警报(response.authResponse.accessToken);
},对);
});
document.addEventListener('deviceready',function(){
试一试{
//警报('设备已准备就绪!请确保将应用程序id设置在此警报之下');
init({appId:{MYAPPID HERE}),nativeInterface:CDV.FB,useCachedDialogs:false});
document.getElementById('data').innerHTML=“”;
}捕获(e){
警报(e);
}
},假);
当您使用Facebook登录连接到Phonegap应用程序时,Facebook会话存储在Phonegap应用程序数据空间的“内部”。这可能是因为在调用FB.login函数时使用了Facebook API。我将为您提供两个场景,以便您更好地理解:
- Phonegap应用程序未呼叫Facebook登录和Facebook应用程序登录: FB.getLoginStatus状态返回未知
- 呼叫Facebook登录后Phonegap应用程序和未登录的Facebook应用程序:FB.getLoginStatus状态返回已连接