Facebook UserName WPF

偶尔善良 提交于 2019-12-11 06:57:56

问题


Its very simple question, I'm new to this and I can't understand the problem , I am trying to get the user name and display it in a label , when i try this code to get the access token it doesn't enter the condition : it enters the event of (browser_navigated) but not the Conditions in , anyone knows whats the problem ?

private void webBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
        FacebookOAuthResult result;

        if (FacebookOAuthResult.TryParse(e.Uri, out result))
        {       
            if (result.IsSuccess)
            {
                var accesstoken = result.AccessToken;
            }
            else
            {
                var errorDescription = result.ErrorDescription;
                var errorReason = result.ErrorReason;
            }
        }

回答1:


There is an annoying bug in wpf browser control which ignores everything after #. (This is only for web browser controls based on wpf so it is present in silverlight and wp7 web browser controls as well.)

Facebook returns access token as part of url fragment.

https://url.com#access_token=....

Due to the bug, when you pass e.Uri as a parameter it doesn't part #access_token=.. thus fb c# sdk thinks it is not a valid oauth callback url and thus TryParse always returns false.

Solution: Either use the winforms browser control for login or set response_type as code token and then exchange code for access token.



来源:https://stackoverflow.com/questions/9044657/facebook-username-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!