FB.如果选择“取消”,则登录不调用回调

FB.login not calling callback if cancel is selected

本文关键字:登录 调用 回调 如果 选择 取消 FB      更新时间:2023-09-26

如果用户没有授予publish_stream权限,我正在尝试获得用户权限。

我有这个功能:

        function AskPermission()
        {
            ResizeUnity(0);
            FB.login(function(response)
            {
                alert("Hit");
                if (response.authResponse) 
                {
                    alert('Granted!');
                    GetUnity().SendMessage("POST", "POST", "Granted");
                }
                else 
                {
                    alert('User cancelled login or did not fully authorize.');
                    GetUnity().SendMessage("POST", "POST", "");
                }
                ResizeUnity(1);
            }, {scope: 'publish_stream'});  
        }

当它被调用时,弹出一个小窗口询问....想要访问您的公开档案和好友列表。有两个按钮ok和cancel。当按下ok键时,它会转到另一个屏幕询问....我想以你的名义发给你的朋友。再次按2键,确定,跳过。

当我按第一个skip拒绝所有权限时,它不返回任何东西。警报("打击");未被调用。

当我在第一个提示上按下ok时,它会转到第二个弹出窗口,并代表我询问发帖情况。我按下ok,警报"授予"被调用。

当我按跳过时,警报'授予'也被调用,即使我点击跳过。

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

使用此功能检查用户是否授予权限

你可以召回相同的功能,如果用户不允许你的应用程序。更多的帮助在代码,我可以帮助你。:)

更多信息请参见:Fb.getLoginStatus

也许这是发生的,因为你试图打开Facebook登录在一个弹出窗口,但它打开在同一窗口,你调用fb.login。当你点击取消,Facebook试图关闭窗口,但由于它不是由Facebook打开的窗口不会关闭。它从不尝试跟踪回调url。

尝试在配置中使用{display: "touch"}或{display: "page"},像这样:

    function AskPermission()
    {ResizeUnity(0);
        FB.login(function(response)
        {
            alert("Hit");
            if (response.authResponse) 
            {
                alert('Granted!');
                GetUnity().SendMessage("POST", "POST", "Granted");
            }
            else 
            {
                alert('User cancelled login or did not fully authorize.');
                GetUnity().SendMessage("POST", "POST", "");
            }
            ResizeUnity(1);
        }, {scope: 'publish_stream', display: 'page'});  
    }

为什么不在一个屏幕中请求所需的所有权限呢?但是,请记住,根据facebook文档,开始时要求很少的权限,然后不断增加权限请求。

https://developers.facebook.com/docs/reference/login/权限

试试这个代码

FB.login(function(response) {
   if (response.authResponse) {
     var access_token =   FB.getAuthResponse()['accessToken'];
     console.log('Access Token = '+ access_token);
     FB.api('/me', function(response) {
     console.log('Good to see you, ' + response.name + '.');
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 }, {scope: ''});

希望有帮助