javascript - FB.getLoginStatus not working if user is inactive -
in canvas app (tab page) use code accesstoken if app needs it:
var accesstoken = ""; fb.getloginstatus(function (response) { if (response.authresponse || response.status === 'connected') { accesstoken = response.authresponse.accesstoken; }else { alert( response.status ); } } ); return accesstoken; i works fine. if user opens app , leave 30minutes (or less or more, long time) after functions can't accesstoken return empty string. in console log there aren't error. after if user refresh page fine...
what should can accesstoken anytime?
here's what's going on:
the fb.getloginstatus method done asynchronously, , give callback execute once finished.
in code return accesstoken right after issuing async request, you're not waiting completed.
should like:
fb.getloginstatus(function (response) { if (response.authresponse || response.status === 'connected') { return response.authresponse.accesstoken; } else { alert( response.status ); } }); so might ask "so why work begin with?", answer simple: @ first sdk has authentication data , not need make request fb servers, states in documentation of method:
roundtrips facebook's servers
to improve performace of application, not every call check status of user result in request facebook's servers. possible, response cached. first time in current browser session fb.getloginstatus called, or jd sdk init'd status: true, response object cached sdk. subsequent calls fb.getloginstatus return data cached response.
if try code passing `true', this:
var accesstoken = ""; fb.getloginstatus(function (response) { if (response.authresponse || response.status === 'connected') { accesstoken = response.authresponse.accesstoken; } else { alert( response.status ); } }, true); return accesstoken; then should not work @ all.
Comments
Post a Comment