当用户到达我已经登录的Facebook应用程序时,如何检测取消的权限请求?

时间:2013-07-28 19:35:05

标签: facebook-graph-api facebook-javascript-sdk

我一直在测试javascript sdk的auth /登录代码,我注意到当用户到达我的应用程序未登录到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'});

    });

2 个答案:

答案 0 :(得分:1)

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

之类的api电话

答案 1 :(得分:0)

如果我到达已登录的应用程序然后取消授权,我在尝试测试auth响应时想出了我正在忽略的内容。我需要确保我还没有授权应用程序! DUH对吗?!! 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'}); 



  });