how do I detect a cancelled permissions request wh

2019-09-01 20:58发布

I've been testing the auth/login code for the javascript sdk and I've noticed that facebook only detects the cancelled permissions request when a user arrives at my app not logged into facebook, but if a user is already logged in to facebook and they cancel the same permissions request, FB.login doesn't return the "unknown" status the way it does under the first condition.

$("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条回答
虎瘦雄心在
2楼-- · 2019-09-01 21:25

I figured out what I was overlooking while trying to test the auth response I'd get if I arrived at my app already logged in and then cancelled authorization. I needed to make sure I hadn't already authorized the app!!! DUH right?!! Anywho, I needed to remove the app from my person app listing on my fb home page, and then I could arrive at my landing page as if I was a fresh new user.

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



  }); 
查看更多
劫难
3楼-- · 2019-09-01 21:44

If you want to verify that you've been granted all the needed permissions, then you can make an api call like FB.api('/me/permissions', function(perms) { ... });

查看更多
登录 后发表回答