身份验证错误 e.Message = OAuth 错误 = 权限+错误 [英] Authentication Error e.Message = OAuth Error = Permissions+error

查看:24
本文介绍了身份验证错误 e.Message = OAuth 错误 = 权限+错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 xamarin.android 和 xamarin.ios (PCL) 项目中使用 Xamarin.Auth 1.5.0.3 版,用于使用 Facebook 的 OAuth API 进行应用程序身份验证/登录.在我点击不是现在"链接(观看下面的屏幕截图)后,问题出现了.我收到以下错误对话框:

I'm using Xamarin.Auth version 1.5.0.3 in my xamarin.android and xamarin.ios (PCL) project for application authentication/login with facebook's OAuth API. The issue arises after I click on the "Not now" link (watch the screenshot below). I get the following error dialog:

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

Authentication Error e.Message = OAuth Error = Permissions+error

有什么方法可以禁用此链接或以某种方式修复它?或者有人知道为什么会发生这种情况吗?

Is there any way to disable this link or to fix it somehow? Or does someone have an idea why this happens?

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

iOS code (which works now):

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"方法.最后,我在 iOS 上调用PresentViewController",在 Android 上调用activity.StartActivity".

But it still doesn't work on Android. All the code is the same, except on iOS i override the "ViewDidAppear" method and on android the "OnElementChanged" method. And at the end i call "PresentViewController" on iOS and "activity.StartActivity" on Android.

我在这里遵循了一些说明:如何登录到 Xamarin.Forms 中的 Facebook

I followed some instructions here: How to login to facebook in Xamarin.Forms

推荐答案

点击Not now"链接时,有隐藏对话框的方法:

When the "Not now" link clicked, there is the method to hide dialog with error:

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

这篇关于身份验证错误 e.Message = OAuth 错误 = 权限+错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆