2013-04-04 48 views
2

如果用户没有授予publish_stream权限,我想获得用户权限。如果选择取消,FB.login不会调用回调

我有这样的功能:

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

当它被称为一个小窗口弹出,询问....想访问您的公开资料和好友列表。有2个按钮好吧,取消。当Okay按下时,它会进入另一个屏幕,询问....是否想代表您发布给您的朋友。再次2按钮,好吧,跳过。

当我按下第一个跳过拒绝所有权限时,它不会返回任何内容。警报(“Hit”);不叫。

当我在第一个提示上按OK时,它会进入第二个弹出窗口并询问是否代表发帖。我按OK,警告'授予'被称为。

当我按下跳过时,即使我点击跳过,也会提示'授予'。

+0

在Android恰好具有从Unity同样的问题 - 回调不叫,如果用户点击小“x”取消按钮。 – Fattie 2014-05-01 15:06:21

回答

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

0

是否有一个原因,为什么不要求所有的权限,以在一个屏幕本身的需要。 Howevern,请记住,按照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: ''}); 

希望帮助

1

也许这种情况正在发生,因为你试图在弹出打开Facebook登录,但在同一个窗口中打开,你称为fb.login。当您点击取消时,Facebook会尝试关闭该窗口,但由于未通过Facebook打开,该窗口不会关闭。它从不尝试跟踪回调url。

尝试使用在配置{显示:“触摸”}或{显示:“页”}这样的:

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'}); 
    } 
相关问题