how do I detect a cancelled permissions request when the user arrives at my facebook app already logged in?

空扰寡人 提交于 2019-12-11 19:22:07

问题


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

    });

回答1:


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) { ... });




回答2:


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



  }); 


来源:https://stackoverflow.com/questions/17912039/how-do-i-detect-a-cancelled-permissions-request-when-the-user-arrives-at-my-face

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!