SL4 Facebook application no longer retrieves access_token

天大地大妈咪最大 提交于 2019-12-12 06:02:40

问题


I have an SL4 Out of Browser application which has been working for several months. As of right now, it appears it will not longer retrieve an access_token from Facebook. I am using facebook-c#-sdk v4.1.1. Some partial code is posted below:

    void FacebookLoginBrowser_Loaded(object sender, RoutedEventArgs e)
    {
        if (!loggedIn)
        {
            LoginToFacebook();
        }
    }

    private void LoginToFacebook()
    {

        dynamic parms = new System.Dynamic.ExpandoObject();
        parms.display = "popup";
        parms.client_id = appId;
        parms.redirect_uri = successUrl;
        parms.cancel_url = failedUrl;
        parms.scope = requestedFbPermissions;
        parms.type = "user_agent";

        loggingInUri = fbApp.GetLoginUrl(parms);

        FacebookLoginBrowser.Source = (loggingInUri);

    }

Below is the code for the html page the browser is redirected to:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    Complete
</body>
<script type="text/javascript">
    window.external.notify(window.location.href);
</script>
</html>

The javascript then fires the following:

    private void FacebookLoginBrowser_ScriptNotify(object sender, NotifyEventArgs e)
    {

        if (e.Value != "Failed")
        {
            string url = e.Value.Replace('#', '?');

            url = HttpUtility.UrlDecode(url);

            Uri ur = new Uri(url);

            string[] str = ur.Query.Split('&');
            access_token =  str[0].Split('=')[1];

            if(!String.IsNullOrEmpty(access_token)){
                fbApp = new FacebookApp(access_token);

                App app = (App)Application.Current;
                app.Fuid.fbApp = fbApp;

                loggedIn = true;
                loginSucceeded(e);
            }

        }

        if (fbApp.Session == null)
        {

            failedLogin();
        }
    }

It appears the querystring which normally contains the access_token value is not longer there. Using Fiddler, I was able to see the redirect from facebook which does contain the access_token value. I am not sure where it is being lost at. Let me know if any one needs any additional information. Thanks!


回答1:


There has been a change in Facebook behavior regarding the structure of the query string. This is discussed in http://facebooksdk.codeplex.com/discussions/261528. My code uses WPF and not Silverlight; I'm not sure whether the same issue applies to the Silverlight control.

Note that the current version of Facebook C# SDK is 5.0.40 per http://facebooksdk.codeplex.com/.

Also see Does Facebook Client-Side Flow still give out access tokens?.



来源:https://stackoverflow.com/questions/6286807/sl4-facebook-application-no-longer-retrieves-access-token

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