2

为了检查用户是否提供了我的应用程序所需的所有权限,我这样做:

/*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' });
}

这边走:

  • 如果用户已经完成:打开一个弹出窗口不到一秒钟

  • 如果用户还没有:显示权限对话框

问题是:在第一种情况下,如何防止对话框打开(可能在后台运行)?

4

2 回答 2

2

使用时无法停止弹出窗口FB.login

在第一种情况下使用服务器端身份验证或用于FB.getLoginStatus防止弹出。

FB.getLoginStatus 允许您确定用户是否已登录 Facebook 并已对您的应用进行身份验证

参考Facebook 文档

来自上述参考链接的片段,

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 以 status: true 初始化,响应对象将被 SDK 缓存。对 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 服务器的请求数,从而降低应用程序的性能。

于 2012-05-21T14:44:40.577 回答
0

facebook sdklogin()函数默认打开一个弹出窗口,您可以在文档中阅读。

所以这不是你想要的方式。有 2 个类似的问题,您可能会发现它的信息很有用。

试试这个这个

于 2012-05-21T14:09:27.110 回答