Uncaught ReferenceError: checkLoginState not detected using facebook API

I am trying to fix this code, but I am stuck in this error on my console:

Uncaught ReferenceError: checkLoginState is undefined.

I just followed this guide . Here is my code for this function and when I call it:

function checkLoginState() { FB.getLoginStatus(function(response) { statusChangeCallback(response); }); } <fb:login-button data-max-rows="1" data-size="large" data-show-faces="false" data-auto-logout-link="true" onlogin="checkLoginState();" scope="public_profile, pages_show_list"></fb:login-button> 
+5
source share
2 answers

It:

 function checkLoginState() { FB.getLoginStatus(function(response) { statusChangeCallback(response); }); } 

Must be inside the <script> block

 <script> function checkLoginState() { FB.getLoginStatus(function(response) { statusChangeCallback(response); }); } // Load the SDK asynchronously (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> 
+3
source

If you keep facebook sdk in your custom js file, Keep checkLoginState() outside of $(document).ready(function () {}); . Here's how it worked for me

0
source

Source: https://habr.com/ru/post/1242712/


All Articles