Facebook SDK for Javascript, FB.login() callback not firing (async call never gets a response?) -
Facebook SDK for Javascript, FB.login() callback not firing (async call never gets a response?) -
the below code facebook api javascript
far. it's pretty simple, bunch of console.log()
s follow code flow. (i recognize naming arguments response , response2 terrible practice it's set avoid naming conflicts).
as stands, fb.init()
succeeds, fb.getloginstatus()
works, , 2 fb.api()
calls work, fb.login()
never happens. async though console.log()
s before , after execute. summarize, console output is:
makes here makes here too permissions: object {data: array[37]} see you, my-name-is-here.
i guess it's because async fb.login()
phone call never gets response callback never fires, no console.log()
s within function. need fb.login()
in order extended permission ads_management
. thought wrong, or @ to the lowest degree direction go solving myself?
window.fbasyncinit = function() { fb.init({ appid: 'my-app-id-is-here', xfbml: true, version: 'v2.0' }); fb.getloginstatus(function(response) { if (response.status === 'connected') { fb.api('/me', function(response2) { console.log("good see you, " + response2.name + "."); }); fb.api('/me/permissions', function(response2) { console.log("permissions:"); console.log(response2); }); console.log("makes here"); fb.login(function(response2) { console.log("why not here?"); if (response2.authresponse) { console.log("response login asking ads_management permission"); console.log(response2); } else { console.log("user cancelled login or did not authorize."); } }, { scope: 'ads_management', return_scopes: true }); console.log("makes here too"); } else { // filled other code doesn't effect question yet } }); };
update: taking away parameters argument {scope: 'ads_management', return_scopes: true}
makes fb.login()
phone call @ to the lowest degree attempted, in console there error:
"fb.login() called when user connected."
but thought way more permissions when user logged in calling fb.login()
again, desired permissions specified in parameters argument.
your flow not correct. first check permission in fb.api("/me/permissions")
callback (since facebook api calls asynchronous), , if particular permission not yet granted, phone call fb.login()
.
here go-
if (response.status === 'connected'){ fb.api('/me/permissions', function(response){ var haspermission = false; var response = new array(); response = response.data; response.map(function (data) { if (data.permission == "ads_management" && "status" == "granted") { haspermission = true; } }); if(!haspermission) // phone call fb.login() here }); }
javascript facebook facebook-graph-api facebook-javascript-sdk facebook-ads-api
Comments
Post a Comment