Logging out of Facebook C# SDK on WP7

我的未来我决定 提交于 2019-12-22 05:18:25

问题


I am trying to add a feature for logging out, which is called in the click event of a ApplicationBarMenuItem, following the instructions on this blog

This is what my code looks like:

    var oauth = new FacebookOAuthClient();

    var logoutParameters = new Dictionary<string, object>
          {
              { "next", "http://www.facebook.com" }
          };

    var logoutUrl = oauth.GetLogoutUrl(logoutParameters);

    LayoutRoot.Children.Add(FacebookLoginBrowser);
    FacebookLoginBrowser.Navigate(new Uri(logoutUrl.AbsoluteUri, UriKind.Absolute));

What I expected this code would do is log the user out of Facebook when the Navigated event completes and then displays whatever URL is passed in the parameter (in this case facebook.com). However, what I'm seeing is that it always loads "http://m.facebook.com/" regardless of what is passed in and it does not logout of Facebook. I don't care what it loads after (that would be great, but at this point I just want it to do the logout action so the user can quit and login when they launch my app again). The only way I can successfully logout a user is if they understand when the page loads that they need to scroll down, zoom in, and click "logout" manually at the bottom of the page - which just isn't an acceptable user experience.

I also downloaded the sample code from that blog and it does roughly the same.

I've seen this and this post and the URL used is pretty close to what is returned by oath.GetLogoutUrl(logoutParameters), but I tried constructing the exact URL with the same result:

var logoutUrl = new Uri("https://www.facebook.com/logout.php?next=http://www.facebook.com&access_token="+fbClient.AccessToken);

This is definitely a ship stopper for my app, so any help or suggestions anyone can provide would be much appreciated!


回答1:


Apparently it's broken on Facebooks side: http://bugs.developers.facebook.net/show_bug.cgi?id=17217




回答2:


It turns out the problem was that the domain in the redirect URL did not match the one provided as the Site Domain in the app settings on Facebook. Obviously, no one could see that because you don't have access to my app settings, but it is a bit of a clue that my app couldn't be registered with "http://www.facebook.com" (as I believe the domain has to be unique).

The solution is to use my own website in the next parameter, which in my case is thecruxapp.com. Also, session_key and api_key were required, so in the end the code that worked for me was:

string logout_format = "http://www.facebook.com/logout.php?api_key={0}&session_key={1}&next={2}";
string access_token = HttpUtility.UrlDecode(fbClient.AccessToken);
char[] tokenSeparator = new char[] { '|' };
string session = access_token.Split(tokenSeparator)[1];

FacebookLoginBrowser.Navigate(new Uri(string.Format(logout_format, apiKey, HttpUtility.UrlEncode(session), HttpUtility.UrlEncode("http://thecruxapp.com"))));

I am not experiencing the bug that was linked to in another answer and it wasn't related - both logout and the redirect occur just fine as long as the URL passed into the next parameter matches the Site Domain entered in the apps settings on Facebook.




回答3:


Have the same issue, no web app as a backend for my WP7 app. i found this solution useful http://claudiufarcas.blogspot.com/2011/06/wp7-webbrowser-caching-and-facebook.html but made some changes to the code as there have been some changes to facebook's rendered HTML since the post.

this was working for me http://blog.jocelynenglund.com/?p=21



来源:https://stackoverflow.com/questions/6240468/logging-out-of-facebook-c-sharp-sdk-on-wp7

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