Skip to content

Instantly share code, notes, and snippets.

@abi
Created July 10, 2010 07:08
Show Gist options
  • Save abi/470531 to your computer and use it in GitHub Desktop.
Save abi/470531 to your computer and use it in GitHub Desktop.
/*
Context for this gist in this blogpost: http://blog.abi.sh/2010/debugging-facebook-connect-locally/
Call setFBCookie(response) inside when you login and receive a response object like here:
FB.Event.subscribe('auth.sessionChange', function(response) {
if (response.session) {
setFBCookie(response);
//Just printing out the name to make sure everything's right.
FB.api('/me', function(response) {
console.log(response.name);
});
}
});
*/
//Change this to something else when running the app remotely since you presumably want to let FBJS do its thing.
var ENV = "LOCAL";
function setFBCookie(response){
if("ENV" == "LOCAL"){
console.log("Running custom cookie function.");
var sep = '&';
var encode = encode === false ? function(s) { return s; } : encodeURIComponent;
var pairs = new Array();
for (var p in response.session){
var val = response.session[p];
var key = p;
if (val !== null && typeof val != 'undefined') {
pairs.push(encode(key) + '=' + encode(val));
}
}
pairs.sort();
pairs = pairs.join("&");
setCookie('fbs_%s',pairs);
}else{
console.log("Not running custom cookie function");
}
}
function setCookie(szName, szValue, szExpires, szPath, szDomain, bSecure)
{
var szCookieText = szName + '=\"' + szValue + '\"';
szCookieText += (szExpires ? '; EXPIRES=' + szExpires.toGMTString() : '');
szCookieText += (szPath ? '; PATH=' + szPath : '');
szCookieText += (szDomain ? '; DOMAIN=' + szDomain : '');
szCookieText += (bSecure ? '; SECURE' : '');
document.cookie = szCookieText;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment