在 WP7 上注销 Facebook C# SDK

发布于 2024-11-13 06:51:45 字数 1440 浏览 2 评论 0原文

我正在尝试添加一个注销功能,该功能在 ApplicationBarMenuItem 的单击事件中调用,遵循 此博客上的说明

这就是我的代码的样子:

    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。我不在乎它之后加载什么(这很好,但此时我只想它执行注销操作,以便用户在再次启动我的应用程序时可以退出并登录)。我可以成功注销用户的唯一方法是,如果他们了解页面加载时需要向下滚动、放大并手动单击页面底部的“注销” - 这不是可接受的用户体验。

我还从该博客下载了示例代码,它的作用大致相同。

我见过这个这篇文章 和使用的 URL 非常接近 oath.GetLogoutUrl(logoutParameters) 返回的内容,但我尝试构建确切的 URL具有相同的结果:

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

这绝对是我的应用程序的一个障碍,因此任何人都可以提供的帮助或建议将不胜感激!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

残疾 2024-11-20 06:51:45

显然它在 Facebook 方面被破坏了: http://bugs.developers.facebook.net/ show_bug.cgi?id=17217

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

丑丑阿 2024-11-20 06:51:45

事实证明,问题在于重定向 URL 中的域与 Facebook 应用程序设置中提供的站点域不匹配。显然,没有人可以看到这一点,因为您无权访问我的应用程序设置,但这是我的应用程序无法通过“http://www.facebook.com”注册的一点线索(因为我相信该域必须是唯一的)。

解决方案是在下一个参数中使用我自己的网站,在我的例子中是 thecruxapp.com。另外,session_key 和 api_key 是必需的,所以最终对我有用的代码是:

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

我没有遇到另一个答案中链接到的错误,并且它不相关 - 只要注销和重定向都发生得很好因为传递到下一个参数的 URL 与 Facebook 应用程序设置中输入的站点域相匹配。

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.

柠檬 2024-11-20 06:51:45

有同样的问题,没有网络应用程序作为我的 WP7 应用程序的后端。
我发现这个解决方案很有用 http://claudiufarcas.blogspot。 com/2011/06/wp7-webbrowser-caching-and-facebook.html 但对代码进行了一些更改,因为 facebook 发生了一些更改自发布以来呈现 HTML。

这对我有用 http://blog.jocelynenglund.com/?p=21

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文