为了检查用户是否提供了我的应用程序所需的所有权限,我这样做:
/*Solo hacemos la peticion si el checkbox estaba desmarcado. Nota: esta funcion asume que solo hay un checkbox en el dom*/
if($('input:checkbox').prop('checked')){
FB.login(function(response){
console.log(response.status);
if (response.status == 'connected') {
hi /* Entonces listo */
}else{
/* Entonces cancelamos el checkbox */
$('input:checkbox').removeAttr('checked');
}
}, { scope: 'publish_stream' });
}
这边:
如果用户全部完成:弹出窗口打开不到一秒钟
如果用户尚未显示:将显示权限对话框
问题是:在第一种情况下,如何防止对话框被打开(可能在后台运行它(?
使用 FB.login
时无法停止弹出窗口。
使用服务器端身份验证或使用FB.getLoginStatus
来防止在第一种情况下弹出。
FB.getLoginStatus允许您确定用户是否已登录到 脸书并已对您的应用进行身份验证
参考脸书文档
来自上述参考链接的片段,
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// 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
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
这就是你所需要的。
编辑:(在OP的评论之后(
可能是Facebook正在缓存旧结果。从我上面提到的同一链接,
往返Facebook的服务器
为了提高应用程序的性能,并非每次调用都要检查 用户的状态将导致向Facebook的服务器发出请求。 在可能的情况下,将缓存响应。第一次在当前 调用FB.getLoginStatus的浏览器会话,或者JD SDK是 初始化状态:true,响应对象将由 软件开发工具包。对FB.getLoginStatus的后续调用将从中返回数据 缓存的响应。
这可能会导致用户登录(或注销(的问题 自上次完整会话查找以来的Facebook,或者如果用户有 在他们的帐户设置中删除了您的应用程序。
要解决此问题,您可以使用第二个调用FB.getLoginStatus。 参数设置为 true 以强制往返 Facebook - 有效地 刷新响应对象的缓存。
FB.getLoginStatus(function(response) {
// this will be called when the roundtrip to Facebook has completed
}, true);
如果您在每次页面加载时调用FB.getLoginStatus,请注意不要 为每个设置此参数,因为它将显着增加 对Facebook服务器的请求数量,从而减少 应用程序的性能。
Facebook sdk login()
函数默认会打开一个弹出窗口,您可以在文档中阅读。
所以这不是你想走的路。您可能会发现 2 个类似的问题,它的信息很有用。
试试这个和这个。