Facebook c#sdk客户端登录+xulrunner cookie

本文关键字:+xulrunner cookie 登录 客户端 c#sdk Facebook | 更新日期: 2023-09-27 18:00:42

我正在尝试用Facebook C#SDK制作一个应用程序,我使用xulrunner+Gecko Fx作为浏览器,我可以登录,但我需要使用多个帐户登录。。我在登录后删除了所有cookie,我也可以使用其他帐户登录并保留访问令牌,我可以发送或获取帖子。。但是当我试图用我的程序在脸书上看到任何页面时,我都看不到,因为我删除了cookie,它需要再次登录。。我厌倦了一切,但找不到任何解决方案,

感谢

Facebook c#sdk客户端登录+xulrunner cookie

您不应该只删除cookie,而应该保存它们,并在需要时恢复正确的cookie集。大致如下:

function removeAndReturnCookies(host)
{
  var removedCookies = [];
  var cookieManager = Components.classes["@mozilla.org/cookiemanager;1"]
                                .getService(Components.interfaces.nsICookieManager2);
  var e = cookieManager.getCookiesFromHost(host);
  while (e.hasMoreElements())
  {
    var cookie = e.getNext().QueryInterface(Components.interfaces.nsICookie2);
    cookieManager.remove(cookie.host, cookie.name, cookie.path, false);
    removedCookies.push(cookie);
  }
}
function restoreCookies(cookies)
{
  var cookieManager = Components.classes["@mozilla.org/cookiemanager;1"]
                                .getService(Components.interfaces.nsICookieManager2);
  for (var i = 0; i < cookies.length; i++)
  {
    var cookie = cookies[i];
    cookieManager.add(cookie.host, cookie.path, cookie.name, cookie.value,
                      cookie.isSecure, cookie.isHttpOnly, cookie.isSession,
                      cookie.expiry);
  }
}
var cookies = removeAndReturnCookies("facebook.com");
restoreCookies(cookies);

我没有测试这个代码,但类似的东西应该可以工作。文档链接:

  • nsICookieManager
  • nsICookieManager2(继承自nsICookieManager
  • nsICookie
  • nsICookie2(继承自nsICookie