简体   繁体   中英

If FB.init({status:true}) causes the Javascript SDK to load status, how can I get the status?

If FB.init({status:true}) causes the Javascript SDK to load status, what is the most efficient way I can get the status?

Do I have to use the async call to FB.getLoginStatus() ? Or is there a synchronous way to get the status that would save a web request?

If you want to do it using JavaScript, then the only way is to make FB.getLoginStatus() call. However, if you are worried about, say, slow response time, then you could simply save the status in a cookie once a successful authorization process is completed.

Though, since we are talking about milliseconds, I would discourage you from going that way.

The most efficient way to retrieve the status is subscribing to the auth.authRepsonseChange event.

example:

 var auth_response_change_callback = function(response) { console.log("auth_response_change_callback"); console.log(response); }; FB.Event.subscribe('auth.authResponseChange', auth_response_change_callback); 

Source: FB event documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM