0

我一直在测试 javascript sdk 的身份验证/登录代码,我注意到 facebook 仅在用户到达我的应用程序但未登录 facebook 时检测到取消的权限请求,但如果用户已经登录到 facebook 和他们取消了相同的权限请求,FB.login 不会像在第一个条件下那样返回“未知”状态。

$("button").click(function(){            

    FB.login(function(response) {

        /*when the user clicks the button but isn't logged in, fb will prompt
        them to log in and then shows the dialogue where I request
        permissions. If I hit cancel, the response status will return
        "unknown" and I redirect to another page. */    

        if(response.status === "unknown"){
            top.location.href = "https://developers.facebook.com/docs/facebook-login/access-tokens/";

        }else{
            /*However if the user is already logged in and the permissions
            request is cancelled, the code goes into this block that is meant to
            handle a "connected" response */

            console.log("connected");                           
            },{scope: 'user_location,user_likes'});

    });
4

2 回答 2

1

如果您想验证您是否已获得所有需要的权限,那么您可以进行 api 调用,例如FB.api('/me/permissions', function(perms) { ... });

于 2013-07-30T05:12:45.707 回答
0

如果我到达我的应用程序已经登录然后取消授权,我在尝试测试我会得到的身份验证响应时发现了我忽略的内容。我需要确保我尚未授权该应用程序!!!对吧?!!Anywho,我需要从我的 fb 主页上的个人应用列表中删除该应用,然后我可以像新用户一样到达我的登录页面。

FB.login(function(response) {
               console.log(response);

              if(response.status === "connected"){

                 //here I have ajax method for passing the signed request to my php page



               }else if(response.status === "not_authorized"){

//if they arrive logged in, are prompted to accept permissions, then cancel 
    //permissions request  

                   console.log("authCancelled");

                   }

                   else{


              //if user arrives at app not logged in they'll be prompted to log in,
    // if they log in and then cancel the permissions request, I'll get an auth response of "unknown" 
//and then I redirect the page.

                   top.location.href = "my redirect url";


              }

     },{scope: 'user_location,user_likes'}); 



  }); 
于 2013-07-28T20:30:15.450 回答