2

I'm trying to get the users permission if they haven't granted the publish_stream permission.

I have this function:

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

When it's called a small window pops up asking .... would like to access your public profile and friends list. There's 2 buttons Okay and cancel. When Okay is pressed it goes on to another screen asking .... would like to post to your friends on your behalf. Again 2 button, Okay and Skip.

When I press the first skip denying all permissions it doesn't return anything. the alert("Hit"); is not called.

When I do press Okay on the first prompt it goes on to the second popup and asks about the posting on behalf. I press Okay, the alert 'Granted' is called.

When I press skip the alert 'Granted' is also called even though I hit skip.

4

3 回答 3

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

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

如果用户不允许您的应用,您可以调用相同的功能。如需更多代码方面的帮助,我可以为您提供帮助。:)

有关更多信息,请参阅:Fb.getLoginStatus

于 2013-04-09T11:09:04.330 回答
1

可能发生这种情况是因为您试图在弹出窗口中打开 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'});  
    }
于 2014-03-31T15:47:39.713 回答
0

是否有理由不要求在一个屏幕本身中获得所需的所有权限。但是,请记住,根据 facebook 文档,开始时要求很少的权限,然后在旅途中不断增加权限请求。

https://developers.facebook.com/docs/reference/login/#permissions

试试这个代码

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

希望有帮助

于 2013-04-15T15:46:35.267 回答