javascript - How to get access token from node-webkit for a desktop app without hosting page? -
i'm trying create desktop app node-webkit. part of app require utilize of facebook get/post content profile (facebook user) utilize desktop app on personal computer.
regarding facebook api documentation (https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.0) , have manually implement login flow , utilize next uri redirect uri: https://www.facebook.com/connect/login_success.html
currently, in node-webkit app, via kid window (a popup), user can login facebook , authorize desktop app interact it's profile. here part of code:
var url = "https://www.facebook.com/dialog/oauth?client_id=myclientid&redirect_uri=https://www.facebook.com/connect/login_success.html&response_type=token&scope=publish_actions"; loginwindow = window.open(url, 'login facebook', 'location=yes,toolbar=yes,menubar=yes,directories=yes,status=yes,resizable=yes,scrollbars=yes,height=480,width=640', false);
after that, user redirected next uri , mentioned in doc, access token appear correctly:
https://www.facebook.com/connect/login_success.html#access_token=thebigtokenstring&expires_in=3864
.
but appears few seconds , after url replaced https://www.facebook.com/connect/blank.html#_=_
(with security warning message).
i've read post propose add together eventlistener hashchange
opened window in order capture access token. after redirect within kid window, i'm no longer available interact via javascript.
so finally, can't access token kid window has retrieved , create visible few seconds.
is can help me user access token node-webkit? don't want utilize server (for hosting web page) between desktop app , facebook.
thanks in advance help.
with help of other question (here) found solution problem.
i post code utilize , hope help else:
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 check if token in url window.hashupdate = function() { if(window.loginwindow.closed){ window.clearinterval(intervalid); start(); //just callback i'm using start part of application (after caught token) } else { var url = window.loginwindow.document.url; var taburl = url.split("#"); //first split separate domain part , parameter part var paramstring = taburl[1]; //i concerned sec part after '#' if(paramstring != undefined){ var allparam = paramstring.split("&"); (var = 0; < allparam.length; i++) { var oneparamkeyvalue = allparam[i].split("="); response[oneparamkeyvalue[0]] = oneparamkeyvalue[1]; //store token in form of key => value }; //close window after 1500ms settimeout(function(){ window.loginwindow.close(); }, 1500); } } } //open url , start watching process window.loginwindow = window.open(this.url, 'login facebook', false); this.intervalid = window.setinterval("window.hashupdate()", 500);
javascript facebook node.js facebook-graph-api node-webkit
No comments:
Post a Comment