Facebook Javascript SDK localhost error message

I am trying to login to facebook, here is my code:

<body>
<form id="form1" runat="server">
    <div id="fb-root"></div>
    <script>    
        (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_GB/all.js#xfbml=1&appId=221385331301885";
            fjs.parentNode.insertBefore(js, fjs);
    } (document, 'script', 'facebook-jssdk'));
    </script> 
    <div class="fb-login-button" data-show-faces="false" data-width="300"></div>
    <script>
        window.fbAsyncInit = function () {
            FB.init({
                appId: '221385323101885', // App ID
                status: true, // check login status
                cookie: true, // enable cookies to allow the server to access the session
                xfbml: true  // parse XFBML
            });

            // Additional initialization code here
        };

        // Load the SDK Asynchronously
        (function (d) {
            var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
            if (d.getElementById(id)) { return; }
            js = d.createElement('script'); js.id = id; js.async = true;
            js.src = "//connect.facebook.net/en_US/all.js";
            ref.parentNode.insertBefore(js, ref);
        } (document));
    </script>
</form>
</body>

      

When I run this code, I get this error message:

enter image description here

I tried to debug the url in the window using https://developers.facebook.com/tools/debug , however it kept saying the url is not vulnerable: / url below if you want to try debugging it:

https://www.facebook.com/dialog/oauth?api_key=221385331301885&app_id=221385331301885&client_id=221385331301885&display=popup&domain=127.0.0.1&locale=en_GB&origin=1&redirect_uri=https%3A%2F%2Fs-static.ak.fbcdn.net%2Fconnect%2Fxd_proxy.php%23cb%3Df4b3e7f08%26origin%3Dhttp%253A%252F%252F127.0.0.1%253A81%252Ff22a06766%26relation%3Dopener%26transport%3Dpostmessage%26frame%3Df23609e538&response_type=token%2Csigned_request&sdk=joey

      

I modified the hosts file to add an entry for 127.0.0.1 localhost.local to match my Facbook app settings. Below are screenshots of my hosts file and my facebook app settings:

Hosts File

Facbook App Settings

As you can see, the domain is the same both in the hosts file and in the settings of the facebook app. Any ideas on how I can resolve this issue? thank

+3


source to share


3 answers


I think I found your problem, but I'm not sure why this is happening ...

I tried to do exactly what you did, but instead using Mobile Web, I had http: // localhost in the site option (and mobile was empty). And everything worked fine.

When I switched it from website to mobile, I got the same error you reported. Do you have to use the mobile option?

Also, you download fb sdk twice, not sure why, first time with this source:

//connect.facebook.net/en_GB/all.js#xfbml=1&appId=221385331301885



And again with this source:

"//connect.facebook.net/en_US/all.js"

What is the point? What's wrong with this is simple:

<div id="fb-root"></div>
<div class="fb-login-button" data-show-faces="false" data-width="300"></div>
<script>
    window.fbAsyncInit = function () {
        FB.init({
        appId: '221385323101885', // App ID
        status: true, // check login status
        cookie: true, // enable cookies to allow the server to access the session
        xfbml: true  // parse XFBML
        });

        // Additional initialization code here
    };

    // Load the SDK Asynchronously
    (function (d) {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) { return; }
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    } (document));
</script>

      

Hope this solves your problem.

+3


source


Add to Site URL : http://localhost

works for me



+3


source


Now you have to create a virtual host in Apache

0


source







All Articles