身份验证错误e.Message = OAuth错误=权限+错误

时间:2017-07-21 12:02:22

标签: xamarin xamarin.ios xamarin.android facebook-authentication xamarin.auth

我在我的xamarin.android和xamarin.ios(PCL)项目中使用Xamarin.Auth版本1.5.0.3进行应用程序身份验证/使用Facebook的OAuth API登录。点击" Not now"链接(观看下面的截图)。我得到以下错误对话框:

  

身份验证错误e.Message = OAuth错误=权限+错误

有没有办法禁用此链接或以某种方式修复它?或者有人知道为什么会这样吗?

enter image description here

enter image description here

iOS代码(现在可以使用):

public override void ViewDidAppear(bool animated)
{
    base.ViewDidAppear(animated);

    var auth = new OAuth2Authenticator(
        clientId: "myClientId",
        scope: "",
        authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"),
        redirectUrl: new Uri("https://www.facebook.com/connect/login_success.html"),
        isUsingNativeUI: true
    );

    auth.Completed += (sender, eventArgs) =>
    {
        if (eventArgs.IsAuthenticated)
        {

        }
        else
        {

        }
    };

    var errorWasAlreadyTrown = false;
    auth.Error += (object sender, AuthenticatorErrorEventArgs eventArgs) =>
        {
                if (!errorWasAlreadyTrown)
                {
                    OAuth2Authenticator auth2 = (OAuth2Authenticator)sender;
                    auth2.ShowErrors = false;

                    App.SuccessfulLoginAction.Invoke();
                    errorWasAlreadyTrown = true;
                }
        };

    PresentViewController(auth.GetUI(), true, null);
}

但它仍然无法在Android上运行。所有代码都是相同的,除了在iOS上我覆盖" ViewDidAppear"方法和Android上的" OnElementChanged"方法。最后我打电话给#34; PresentViewController"在iOS和" activity.StartActivity"在Android上。

我在此处遵循了一些说明:How to login to facebook in Xamarin.Forms

2 个答案:

答案 0 :(得分:1)

单击“Not now”链接时,有隐藏对话框的方法,错误:

auth.Error += (sender, eventArgs) =>
{
  OAuth2Authenticator auth2 = (OAuth2Authenticator)sender;
  auth2.ShowErrors = false;
  auth2.OnCancelled();
};

答案 1 :(得分:0)

我很难准确地将其同化到您的代码中,因为没有什么可以解决,但您可以尝试的其中一件事就是处理auth.error事件。

auth.Error += (object sender, AuthenticatorErrorEventArgs eventArgs) => {
    auth.IsEnabled = false;
};

xamarin developer thread that can be found here中的讨论可能对您有用。