无法使用Facebook C#SDK注销Facebook [英] Cannot Logout of Facebook with Facebook C# SDK

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

问题描述

我想我已经阅读了关于在桌面应用程序中注销Facebook的内容的所有内容。迄今为止没有什么工作。



具体来说,我想将用户登录,以便他们可以切换身份,例如在家里共享一台电脑的人可以用自己的Facebook帐号使用该软件,但没有机会切换帐号,这是相当凌乱的。 (尚未测试切换Windows用户帐户,因为对于最终用户来说太简单了,不需要)。



现在我应该说我已经设置了应用程序来使用这些权限:

  string [] permissions = new string [] {user_photos,publish_stream ,offline_access}; 

所以,offline_access包含在那里。我不知道这是否/应该影响注销。



同样,我注销的目的只是切换用户。 (如果有一个更好的方法,请让我知道。)



声称的解决方案似乎是:




  • 使用JavaScript SDK(FB.logout())

  • 使用m.facebook.com代替

  • 创建你自己的URL(可能使用m.facebook.com)

  • 创建自己的URL并使用会话变量(在ASP.NET中)



第一种是愚蠢的。当您使用C#时为什么要求JavaScript?这是一个倒退的步骤,在桌面应用程序中有很多额外的开销。 (我没有尝试这样做,因为在桌面应用程序中这样做是令人厌恶的。)如果有人可以确认这是唯一的工作方法,请这样做。我拼命地试图避免它。



第二个不起作用。也许它在过去有效,但我的umpteen试图让它上班都失败了。



第三个不起作用。我尝试了十几个变体,零成功。



最后一个选项对于桌面应用程序不起作用,因为它不是ASP.NET,您没有一个会话变量来处理。



Facebook C#SDK注销也不再有效。即

  public FacebookLoginDialog(string appId,string [] extendedPermissions,bool logout)
{
IDictionary<字符串,对象> loginParameters = new Dictionary< string,object>
{
{response_type,token},
{display,popup}
};

_navigateUri = FacebookOAuthClient.GetLoginUrl(appId,null,extendedPermissions,logout,loginParameters);

InitializeComponent();
}

我记得以前工作,但现在不再工作。 (这真的让我困惑...)



它现在将用户指向Facebook手机页面,用户必须手动注销。



现在,我可以做浏览器自动化来自动点击用户的注销链接,但是如果Facebook更新移动用户界面,这很容易破裂。它也是混乱,可能比尝试使用JavaScript SDK FB.logout()方法(尽管不是太多)更糟糕的解决方案。



我已经搜索了某种文档,但是,我在Facebook开发人员文档中找不到任何说明如何注销应用程序的内容。有没有人解决了这个问题,或看到任何可以移植到Facebook C#SDK中的文档?



如果任何人可以指向可以使用它的文档,我肯定可以使用WebClient或HttpClient / Response。我根本无法找到任何低级文档,说明这种方法是如何工作的。



提前感谢您的任何建议,指针或链接。

解决方案

嗯,我没有任何工作,所以我采取了一个讨厌的黑客。



FacebookOAuthClient.GetLogoutUrl()方法URL不会将我注销,但是它会返回一个m.facebook.comURL,例如:



http:// m .facebook.com / logout.php下一= HTTP:?//www.facebook.com/dialog/oauth/ RESPONSE_TYPE =令牌安培;显示弹出=&安培;范围= user_about_me%252coffline_access&安培; CLIENT_ID = 123456789012345&安培; REDIRECT_URI = HTTP%253A% 252f%252fwww.facebook.com%252fconnect%252flogin_success.html& confirm = 1



手机页面的底部有一个注销链接页。



试图捕捉锚标签:

  HtmlElementCollection hec = wbrFacebookAuth .Document.GetElementsByTagName( A); 
foreach(HtmlElement elem in hec)
{
//注销链接有一个data-sigil =logout属性:
string datasigil = elem.GetAttribute(data-印记)ToLower将();
if(datasigil ==logout)
{
wbrFacebookAuth.Navigate(elem.GetAttribute(href));
break;
}
}

在Navigated WebBrowser事件中是不可预测和不可靠的。捕捉它的实际方法是不相关的。例如这不起作用:

  string logoutPattern = @< a href =(/ logout。[^ ] +) ; 

Regex rx = new Regex(logoutPattern);
if(rx.IsMatch(wbMain.DocumentText))
{
MatchCollection mc = rx.Matches(wbMain.DocumentText);
if(mc.Count> 0)
{
foreach(m中的匹配m)
{
Console.WriteLine(***+ m。的ToString());
}
}
}

但是,可靠地在DocumentCompleted事件处理程序中。

  private void wbrFacebookAuth_DocumentCompleted(object sender,WebBrowserDocumentCompletedEventArgs e)
{
if(_logout)
{
HtmlElementCollection hec = wbrFacebookAuth.Document.GetElementsByTagName(a);
foreach(HtmlElement elem in hec)
{
//注销链接有一个data-sigil =logout属性:
string datasigil = elem.GetAttribute(data-印记)ToLower将();
if(datasigil ==logout)
{
wbrFacebookAuth.Navigate(elem.GetAttribute(href));
break;
}
}
}
}

问题是现在正在加载2页而不是1页,而且还是有点混乱。但是,它是有效的。


I think I've read just about everything out there on the topic of logging out of Facebook inside of a Desktop application. Nothing so far works.

Specifically, I would like to log the user out so that they can switch identities, e.g. People sharing a computer at home could then use the software with their own Facebook accounts, but with no chance to switch accounts, it's quite messy. (Have not yet tested switching Windows users accounts as that is simply far too much to ask of the end user and should not be necessary.)

Now, I should say that I have set the application to use these permissions:

string[] permissions = new string[] { "user_photos", "publish_stream", "offline_access" };

So, "offline_access" is included there. I do not know if this does/should affect logging out or not.

Again, my purpose for logging out is merely to switch users. (If there's a better approach, please let me know.)

The purported solutions seem to be:

  • Use the JavaScript SDK (FB.logout())
  • Use "m.facebook.com" instead
  • Create your own URL (and possibly use m.facebook.com)
  • Create your own URL and use the session variable (in ASP.NET)

The first is kind of silly. Why resort to JavaScript when you're using C#? It's kind of a step backwards and has a lot of additional overhead in a desktop application. (I have not tried this as it's simply disgustingly messy to do this in a desktop application.) If anyone can confirm that this is the only working method, please do so. I'm desperately trying to avoid it.

The second doesn't work. Perhaps it worked in the past, but my umpteen attempts to get it to work have all failed.

The third doesn't work. I've tried umpteen dozen variations with zero success.

The last option there doesn't work for a desktop application because it's not ASP.NET and you don't have a session variable to work with.

The Facebook C# SDK logout also no longer works. i.e.

public FacebookLoginDialog(string appId, string[] extendedPermissions, bool logout)
{
    IDictionary<string, object> loginParameters = new Dictionary<string, object>
                              {
                              { "response_type", "token" },
                              { "display", "popup" }
                              };

    _navigateUri = FacebookOAuthClient.GetLoginUrl(appId, null, extendedPermissions, logout, loginParameters);

    InitializeComponent();
}

I remember it working in the past, but it no longer works now. (Which truly puzzles me...)

It instead now directs the user to the Facebook mobile page, where the user must manually logout.

Now, I could do browser automation to automatically click the logout link for the user, however, this is prone to breaking if Facebook updates the mobile UI. It is also messy, and possibly a worse solution than trying to use the JavaScript SDK FB.logout() method (though not by much).

I have searched for some kind of documentation, however, I cannot find anything in the Facebook developer documentation that illustrates how to logout an application.

Has anyone solved this problem, or seen any documentation that can be ported to work with the Facebook C# SDK?

I am certainly open to using a WebClient or HttpClient/Response if anyone can point to some documentation that could work with it. I simply have not been able to find any low-level documentation that shows how this approach could work.

Thank you in advance for any advice, pointers, or links.

解决方案

Well, I've turned up nothing that works, so I've resorted to a nasty hack.

The FacebookOAuthClient.GetLogoutUrl() method URL does not log me out, however, it does return an "m.facebook.com" URL, e.g.:

http://m.facebook.com/logout.php?next=http://www.facebook.com/dialog/oauth/?response_type=token&display=popup&scope=user_about_me%252coffline_access&client_id=123456789012345&redirect_uri=http%253a%252f%252fwww.facebook.com%252fconnect%252flogin_success.html&confirm=1

The mobile page has a "Logout" link at the bottom of the page.

Trying to catch the anchor tag:

HtmlElementCollection hec = wbrFacebookAuth.Document.GetElementsByTagName("a");
foreach (HtmlElement elem in hec)
{
    // the logout link has a data-sigil="logout" attribute:
    string datasigil = elem.GetAttribute("data-sigil").ToLower();
    if (datasigil == "logout")
    {
    wbrFacebookAuth.Navigate(elem.GetAttribute("href"));
    break;
    }
}

In the Navigated WebBrowser event is unpredictable and unreliable. The actual method of catching it isn't relevant. e.g. This does not work either:

        string logoutPattern = @"<a href=""(/logout.[^""]+)""";

        Regex rx = new Regex(logoutPattern);
        if (rx.IsMatch(wbMain.DocumentText))
        {
            MatchCollection mc = rx.Matches(wbMain.DocumentText);
            if (mc.Count > 0)
            {
                foreach (Match m in mc)
                {
                    Console.WriteLine("*** " + m.ToString());
                }
            }
        }

However, it can be caught reliably in the DocumentCompleted event handler.

private void wbrFacebookAuth_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
   if (_logout)
   {
    HtmlElementCollection hec = wbrFacebookAuth.Document.GetElementsByTagName("a");
    foreach (HtmlElement elem in hec)
    {
        // the logout link has a data-sigil="logout" attribute:
        string datasigil = elem.GetAttribute("data-sigil").ToLower();
        if (datasigil == "logout")
        {
        wbrFacebookAuth.Navigate(elem.GetAttribute("href"));
        break;
        }
    }
   }
}

The problem is that it is now loading 2 pages instead of 1, and it's still a bit messy. However, it works.

这篇关于无法使用Facebook C#SDK注销Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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