facebook - What is the correct setup for the auto-login of a returning, authenticated user with the Javascript SDK? -


hey fellow facebook developers,

i've read dozens of related questions , tried every related example on developers.facebook.com can't 1 work:

  1. a user has visited website , authorized permissions request him via

    fb.login(callback, {     scope: 'publish_actions,user_actions:news,user_interests' }); 

    after calling

    fb.init({     appid: 'xxx', // app id     status: true, // check login status     cookie: true,     xfbml: true // parse xfbml }); 
  2. i can request access token valid time , use query kind of information user.

  3. without logging out anywhere (facebook or own website), if navigate page again (or hit reload), expect able use

    fb.getloginstatus(callback) 

    and receive response of connected. in understanding, user should not have click anymore.

what get, though, unknown. no matter in browser , no matter whether using real developer profile or facebook test user.

i have subscribed events auth.authresponsechange , auth.statuschange fire, if explicitly call fb.login().

it says in example in facebook sdk documentation fb.init() above should necessary information facebook on page load time , events should fire accordingly.

since tried so many examples , think understand documentation, can't see error happens.

is there i'm missing, misunderstanding or timing problem should aware of?

on side note, have tried more mentioned facebook events, forced status update through fb.getloginstatus(callback, true), running code step step entering in javascript console of chrome , more suggestions , facebook forums.

if set status: true, fb.getloginstatus response object cached sdk , subsequent calls fb.getloginstatus return data cached response.

to around this, have call fb.getloginstatus second parameter set true force roundtrip facebook - refreshing cache of response object.

example:

window.fbasyncinit = function() {     fb.init({         appid  : '',         status : true,         cookie : true,         xfbml  : true,     });      fb.getloginstatus( function(response) {         //console.log(response);         if (response.status === 'connected') {             var accesstoken = response.authresponse.accesstoken;             alert(accesstoken);         } else if (response.status === 'not_authorized') {             //login function         } else {             //login function         }     }, true);      fb.event.subscribe('auth.authresponsechange', function(response) {         //console.log('the status of session changed to: '+response.status);         alert(response.status);     }); }; 

documentation: https://developers.facebook.com/docs/reference/javascript/fb.getloginstatus/


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -