【发布时间】:2017-12-27 11:26:51
【问题描述】:
我在我的 xamarin.android 和 xamarin.ios (PCL) 项目中使用 Xamarin.Auth 版本 1.5.0.3 使用 facebook 的 OAuth API 进行应用程序身份验证/登录。当我点击“Not now”链接后,问题就出现了(看下面的截图)。我收到以下错误对话框:
身份验证错误 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”。
我在这里遵循了一些说明:How to login to facebook in Xamarin.Forms
【问题讨论】:
-
我认为您需要处理“重定向”事件。至少这是我从一些文档中了解到的。此外,展示一段 sn-p 代码可能是个好主意,向我们展示您如何从 PCL 调用和处理它。
-
@Digitalsa1nt 如何处理重定向事件?我无法重定向回我的应用程序,因为它不是 Web 应用程序。还是我必须重定向到其他地方?
-
所以'not now'重定向到一个错误页面,该页面调用'auth.error'
标签: xamarin xamarin.ios xamarin.android facebook-authentication xamarin.auth