开发者

Facebook c# sdk client login + xulrunner cookies

I am trying to make an application with Facebook C# SDK,,I am usin xulrunner+Gecko Fx for bro开发者_如何学Cwser,,I can login but I need to login with multiple accounts..I am removing all cookies after login and I can login with other account too and keep access tokens and I can send or get posts..But when i try to see any page on facebook with my program I cant see because i removed cookies and it need login again..I tired everything but couldnt find any solution,

Thanks


You shouldn't just remove the cookies but save them and restore the right set of cookies when it is needed. Something along the lines:

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

I didn't test this code but something like that should work. Documentation links:

  • nsICookieManager
  • nsICookieManager2 (inherits from nsICookieManager)
  • nsICookie
  • nsICookie2 (inherits from nsICookie)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜