The remote procedure call failed

1

This is my first post, so please be easy on me :)

I am doing a tutorial for Facebook SDK, and I am trying to login to the facebook service from a Windows Phone XAML application. It works fine when I follow the steps of the tutorial, and hit the login button to log in, but when I am trying to automate this, I get an error.

The code uses WebAuthenticationBroker, calling WebAuthenticationBroker.AuthenticateAndContinue(LoginUrl);

When I try to put that code inside Loaded event

private void Page_Loaded(object sender, RoutedEventArgs e)
{
    if (this.fbHelper.AccessToken == null)
    {
         WebAuthenticationBroker.AuthenticateAndContinue(LoginUrl); //throws error
    }
    else
    {
        GetUserInfo();
    }
}

I get the following error:

The remote procedure call failed. (Exception from HRESULT: 0x800706BE)

I think the problem is that the page is not ready yet to perform the logic, but I don't really know where should I put the code?

c#
facebook
windows-phone-8.1
asked on Stack Overflow Mar 28, 2015 by Ker Pi • edited Mar 28, 2015 by Ker Pi

1 Answer

0

It seems that Broker can be called once Window is activated. As I've tried it should work when done like this:

public MainPage()
{
    this.InitializeComponent();
    Window.Current.Activated += Current_Activated;
}

private void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
{
    Window.Current.Activated -= Current_Activated;
    Debug.WriteLine("Activated");
    WebAuthenticationBroker.AuthenticateAndContinue(new Uri("https://google.com"));
}

Of course it needs some improvements, but should work. Remember only that Activeted event may be called for number of reasons, for example after a dialog is shown.

answered on Stack Overflow Mar 28, 2015 by Romasz

User contributions licensed under CC BY-SA 3.0