简体   繁体   English

Unity Facebook SDK FB.Login无法正常运行

[英]Unity Facebook SDK FB.Login not functioning properly

When calling FB.Login from the unity facebook plugin (I've tried 4.2.4 and 4.3.3) from within a canvas facebook web app, the callback function is never called when the user hits Cancel when prompted by the facebook dialog to accept the permissions of the app. 当从canvas Facebook Web应用程序中的统一Facebook插件(我尝试过4.2.4和4.3.3)调用FB.Login时,当用户在Facebook对话框提示您接受时单击“取消”时,永远不会调用回调函数应用程序的权限。

Init works fine, the sdk loads, then I call FB.Login with a facebook delegate and if the user cancels, there is no callback. 初始化工作正常,SDK加载,然后我用Facebook委托调用FB.Login,如果用户取消,则没有回调。 You can see this behavior in the example provided in the sdk if you build it as a webapp and create a canvas app in facebook that points to it. 如果将其构建为Web应用程序并在指向它的Facebook应用程序中创建它,则可以在sdk中提供的示例中看到此行为。

Any suggestions? 有什么建议么? I need that callback to continue the flow of my application. 我需要该回调来继续我的应用程序流程。

Thank you. 谢谢。

This issue is caused by the fact that AbstractFacebook simply ignores the entire FBResult argument received from Facebook API, including the "cancelled" parameter when user refuses to grant access privileges to the app. 造成此问题的原因是,当用户拒绝向应用程序授予访问权限时,AbstractFacebook只会忽略从Facebook API接收到的整个FBResult参数,包括“ cancelled”参数。

Decompiled OnAuthResponse method from AbstractFacebook looks like: 从AbstractFacebook反编译的OnAuthResponse方法如下所示:

protected void OnAuthResponse(FBResult result)
{
    Dictionary<string, object> dictionary = new Dictionary<string, object>();
    dictionary["is_logged_in"] = (object) (bool) (this.IsLoggedIn ? 1 : 0);
    dictionary["user_id"] = (object) this.UserId;
    dictionary["access_token"] = (object) this.AccessToken;
    dictionary["access_token_expires_at"] = (object) this.AccessTokenExpiresAt;

    FBResult result1 = new FBResult(Json.Serialize((object) dictionary), result.Error);
    using (List<FacebookDelegate>.Enumerator enumerator = this.authDelegates.GetEnumerator())
    {
        while (enumerator.MoveNext())
        {
            FacebookDelegate current = enumerator.Current;
            if (current != null)
            current(result1);
        }
    }
    this.authDelegates.Clear();
}

If you could override this behavior somehow, maybe you could strip the "cancelled" parameter form JSON stored in result.message. 如果可以某种方式覆盖此行为,则可以从存储在result.message中的JSON中删除“已取消”参数形式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM