0
votes

I'm trying to make a simple Facebook login. I have a new window in which i put a System.Windows.Controls.WebBrowser and then navigate it to

https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=https://www.facebook.com/connect/login_success.html&response_type=token

but after I log in it redirects me to

https://www.facebook.com/connect/login_success.html

where I should have the token but the System.Windows.Controls.WebBrowser control Source property does not give me the complete URL, giving me

https://www.facebook.com/connect/login_success.html instead of https://www.facebook.com/connect/login_success.html#access_token=THE_TOKEN&expires_in=7180

2

2 Answers

3
votes

Look at this answer (MSDN) I think it will solve your problem! You will need:

<Window x:Class="WpfApplicationTest.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
        Title="Window2" Height="300" Width="300">
     <StackPanel>
        <wfi:WindowsFormsHost>
            <wf:WebBrowser Navigated="WebBrowser_Navigated" x:Name="wfwb"/>
        </wfi:WindowsFormsHost>
     </StackPanel>
</Window>
0
votes

just add reference to facebook.dll for c# and make the webbrowser.Navigated event - works for me

private void m_WebBrowser_Navigated(object sender, NavigationEventArgs e)
    {
        Uri url = e.Uri;
        FacebookOAuthResult result;
        dynamic fb = new FacebookClient();

        if (fb.TryParseOAuthCallbackUrl(url, out result))
        {
            if (result.IsSuccess)
            {
                AccessToken = result.AccessToken;
                Window window = Window.GetWindow(this);
                window.Close();                    
            }
            else
            {
                var errorDescription = result.ErrorDescription;
                var errorReason = result.ErrorReason;
            }
        }
    }