我在 xamarin.android 和 xamarin.ios (PCL) 项目中使用 Xamarin.Auth 版本 1.5.0.3 通过 facebook 的 OAuth API 进行应用程序身份验证/登录。我单击“现在不”链接后出现问题(请观看下面的屏幕截图)。我收到以下错误对话框:
身份验证错误 e.Message = OAuth 错误 = 权限+错误
有什么方法可以禁用此链接或以某种方式修复它吗?或者有人知道为什么会发生这种情况?
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”。
我在这里遵循了一些说明:如何在 Xamarin.Forms 中登录 Facebook https://stackoverflow.com/questions/24105390/how-to-login-to-facebook-in-xamarin-forms/24423833#24423833
当单击“现在不”链接时,有一种方法可以隐藏带有错误的对话框:
auth.Error += (sender, eventArgs) =>
{
OAuth2Authenticator auth2 = (OAuth2Authenticator)sender;
auth2.ShowErrors = false;
auth2.OnCancelled();
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)