facebook - FB.login() after FB.getLoginStatus() being blocked on Safari -


i have images want users able post facebook page when click 1 of several buttons on webpage.

<script> fb.getloginstatus(function(response) {   if ( response && response.status == 'connected' )   {     postphotostofacebook();   }   else   {     fb.login(function(response)     {       if ( response && response.status == 'connected' )       {         postphotostofacebook();       }     },     {       scope: 'publish_actions'     });   } }, true); </script> 

it's simple code. checks see if user logged in. if yes, posts pictures facebook. if not logged in, runs fb.login(), makes popup, asking user login facebook , give appropriate permissions app. after login complete, if user logged in , approved permissions, app same above, posts photos facebook.

the fb.login() popup appears blocked on browsers though. why this?

some methods i've seen suggest check see if user logged in when load page. isn't going work in cases because user can switch browser tabs facebook , login/logout. on web app page, might think connected/disconnected when opposite true.

so have check login status every time want post , give user option login if not. if forgo fb.getloginstatus() , run fb.login() if user wasn't logged in when loading page, if switch facebook, login, come web app page, when click button, try run fb.login() javascript error cause user logged in now.

how around problem?

rather calling asynchronous method fb.getloginstatus(), check see fb.getuserid() not null, undefined, or 0.

var userid = fb.getuserid(); if(!!userid){    //user logged in } else {    //user not logged in call } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -