Web 身份验证异常导致 windows phone silverlight 8.1

Exception web authentication result in windows phone silverlight 8.1

我想在我的 windows phone 应用程序中使用 Facebook 登录,当点击登录按钮时会出现来自 Facebook 的弹出窗口,在这里输入我的用户名和密码,很好,当我想要的时候获取令牌,结果

WebAuthenticationResult myResult = await WebAuthenticationBroker.AuthenticateSilentlyAsync(startUri);

我得到这个异常:

COMException was unhandled by user code

An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.ni.dll but was not handled in user code

Additional information: Error HRESULT E_FAIL has been returned from a call to a COM component.

有解决这个问题的方法吗?

使用 WebAuthenticationBroker.AuthenticateAndContinue(requestUri, callbackUri) 代替 WebAuthenticationBroker.AuthenticateSilentlyAsync(startUri),然后在 App.xaml 中添加一个 Application_ContractActivated 事件。您可以通过打开 App.xaml 并像这样添加 ContractActivated

来完成此操作

<shell:PhoneApplicationService ContractActivated="Application_ContractActivated" />

这应该在App.xaml.cs 中添加Application_ContractActivated 方法。在这种方法中,您可以获得如下结果:

public WebAuthenticationBrokerContinuationEventArgs WABContinuationArgs { get; set; }

        private void Application_ContractActivated(object sender, IActivatedEventArgs e)
                {
                    var _WABContinuationArgs = e as WebAuthenticationBrokerContinuationEventArgs;

                    if (_WABContinuationArgs != null)
                    {
                        WABContinuationArgs = _WABContinuationArgs;
                        var result = WABContinuationArgs.WebAuthenticationResult;
                    }
                }

注意 此解决方案适用于 Windows Phone Silverlight 8.1 而不是 Windows Phone 8.1。对于 Windows Phone 8.1,原理相同,但您使用 OnActivated 方法而不是 Application_ContractActivated。