0

我正在尝试进行简单的 Facebook 登录。我有一个新窗口,我在其中放置 aSystem.Windows.Controls.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控制 Source 属性没有给我完整的 URL,给我

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

4

2 回答 2

3

看看这个答案(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>
于 2012-08-28T13:14:54.607 回答
0

只需为 c# 添加对 facebook.dll 的引用并制作 webbrowser.Navigated 事件 - 对我有用

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;
            }
        }
    }
于 2013-09-05T18:33:43.073 回答