我在我的 xamarin.android 和 xamarin.ios (PCL) 项目中使用 Xamarin.Auth 版本 1.5.0.3,通过 facebook 的 OAuth API 进行应用程序身份验证/登录。我单击“现在不”链接后出现问题(请观看下面的屏幕截图)。我收到以下错误对话框:
Authentication Error e.Message = OAuth Error = Permissions+error
有什么方法可以禁用此链接或以某种方式修复它吗?或者有人知道为什么会发生这种情况吗?
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”方法。最后,我在 iOS 上调用“PresentViewController”,在 Android 上调用“activity.StartActivity”。
我按照此处的一些说明进行操作:How to login to facebook in Xamarin.Forms
最佳答案
当点击“现在不”链接时,有隐藏对话框的方法,并出现错误:
auth.Error += (sender, eventArgs) =>
{
OAuth2Authenticator auth2 = (OAuth2Authenticator)sender;
auth2.ShowErrors = false;
auth2.OnCancelled();
};
关于xamarin - 身份验证错误 e.Message = OAuth 错误 = 权限+错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45237177/