Last active
August 29, 2015 14:11
-
-
Save siygle/514c10c95edd0562ab99 to your computer and use it in GitHub Desktop.
get facebook login with js (backup from: http://stackoverflow.com/questions/24314431/how-to-get-access-token-from-node-webkit-for-a-desktop-app-without-hosting-page)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url = "https://www.facebook.com/dialog/oauth?&client_id=myBigClientID&redirect_uri=https://www.facebook.com/connect/login_success.html&response_type=token&scope=publish_actions"; | |
function Response() { | |
this.access_token = null; | |
this.expires_in = null; | |
}; | |
var response = new Response(); | |
//function called every 500ms to check if token is in url | |
window.hashUpdate = function() { | |
if(window.loginWindow.closed){ | |
window.clearInterval(intervalId); | |
start(); //just a callback that I'm using to start another part of my application (after I caught the token) | |
} | |
else { | |
var url = window.loginWindow.document.URL; | |
var tabUrl = url.split("#"); //first split to separate the domain part and the parameter part | |
var paramString = tabUrl[1]; //I concerned only by the second part after the '#' | |
if(paramString != undefined){ | |
var allParam = paramString.split("&"); | |
for (var i = 0; i < allParam.length; i++) { | |
var oneParamKeyValue = allParam[i].split("="); | |
response[oneParamKeyValue[0]] = oneParamKeyValue[1]; //store my token in form of key => value | |
}; | |
//close the window after 1500ms | |
setTimeout(function(){ | |
window.loginWindow.close(); | |
}, 1500); | |
} | |
} | |
} | |
//open the url and start the watching process | |
window.loginWindow = window.open(this.url, 'Login facebook', false); | |
this.intervalId = window.setInterval("window.hashUpdate()", 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment