2012-08-28 61 views
0

我想做一個簡單的Facebook登錄。我在我把System.Windows.Controls.WebBrowser,然後導航到c#WPF WebBrowser

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

但我登錄之後重定向我

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

一個新窗口

我應該有令牌但System.Windows.Controls.WebBrowser控制Sourc Ë財產不給我完整的URL,讓我

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

回答

2

看看在這個answer (MSDN) 我認爲這將解決您的問題! 你將需要:

<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> 
+1

我做了它的工作原理。 WebBrowser,但編程。感謝您的快速回答:P – SiWM

0

只需添加引用facebook.dll爲C#,使webbrowser.Navigated事件 - 使用WindowsFormsHost和System.Windows.Forms的,我

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; 
      } 
     } 
    }