When using WebAuthenticationBroker.AuthenticateAndContinue
in the OnNavigatedTo
event of my MainPage
I get the following exception:
The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
However, if I create a button with a click event which does exactly the same function call, I don't get the exception. I think the reason is that the page isn't fully loaded when the OnNavigatedTo
event is triggered.
So how should I go about creating a page that automatically starts the authorization process when I navigate to it, without having an intermediate control (like a button)?
If I try to execute that token request function on the page Loaded event, I get the same error as you:
String FacebookURL = "https://www.facebook.com/dialog/oauth?client_id=" + Uri.EscapeDataString(FacebookClientID.Text) + "&redirect_uri=" + Uri.EscapeDataString(FacebookCallbackUrl.Text) + "&scope=read_stream&display=popup&response_type=token";
System.Uri StartUri = new Uri(FacebookURL);
System.Uri EndUri = new Uri(FacebookCallbackUrl.Text);
WebAuthenticationBroker.AuthenticateAndContinue(StartUri, EndUri, null, WebAuthenticationOptions.None);
The workaround I used to make this work involves a DispatcherTimer
DispatcherTimer timer = new DispatcherTimer();
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
timer.Interval = new TimeSpan(0, 0, 0);
timer.Tick += timer_Tick;
timer.Start();
}
void timer_Tick(object sender, object e)
{
timer.Stop();
String FacebookURL = "https://www.facebook.com/dialog/oauth?client_id=" + Uri.EscapeDataString(FacebookClientID.Text) + "&redirect_uri=" + Uri.EscapeDataString(FacebookCallbackUrl.Text) + "&scope=read_stream&display=popup&response_type=token";
System.Uri StartUri = new Uri(FacebookURL);
System.Uri EndUri = new Uri(FacebookCallbackUrl.Text);
WebAuthenticationBroker.AuthenticateAndContinue(StartUri, EndUri, null, WebAuthenticationOptions.None);
}
User contributions licensed under CC BY-SA 3.0