登录WP7上的Facebook C#SDK [英] Logging out of Facebook C# SDK on WP7

查看:127
本文介绍了登录WP7上的Facebook C#SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加一个注销功能,这是在ApplicationBarMenuItem的点击事件中调用的,本博客上的说明

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

这是我的代码如下:

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

我期望这个代码会做的是在Navigated事件完成后将用户登出Facebook,然后显示参数中传递的所有URL(本例中为facebook.com)。不过,我看到的是它总是加载 http://m.facebook.com/ 无论通过什么,它不注销Facebook。我不在乎它加载了什么(这将是很棒的,但在这一点上,我只是希望它执行注销操作,以便用户可以在再次启动我的应用程序时退出登录)。我可以成功注销用户的唯一方法是,如果他们了解页面加载时需要向下滚动,放大,并在页面底部手动点击注销 - 这只是不可接受的用户体验。

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.

这篇文章,使用的URL非常接近oath.GetLogoutUrl(logoutParameters)返回的URL,但是我尝试使用相同的结果构造确切的URL :

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!

推荐答案

事实证明,重定向网址中的域与网站域名在Facebook上的应用设置。显然,没有人可以看到,因为你无法访问我的应用程序设置,但这是一个线索,我的应用程序无法注册http://www.facebook.com(因为我相信域必须是唯一的)。

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).

解决方案是在下一个参数中使用我自己的网站,在我的例子中是crcrapp.com。此外,session_key和api_key是必需的,所以最后为我工作的代码是:

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"))));

我没有遇到与另一个答案相关联的错误,它与之无关只要传入下一个参数的网址与Facebook上的应用设置中输入的网站域匹配,退出并重定向就会发生。

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.

这篇关于登录WP7上的Facebook C#SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆