Question

I am using FB Javascript SDK to check that a user like my page or not. It's works on localhost but when I upload this on Server the code does not works. My code is below:

    <script>
    window.fbAsyncInit = function() {
        FB.init({
            appId      : 'My App Id', // App ID

            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true  // parse XFBML
        });

        FB.getLoginStatus(function(response) {
            var page_id = "My Page ID";
            if (response && response.authResponse) {
                var user_id = response.authResponse.userID;
                var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
                FB.Data.query(fql_query).wait(function(rows) {
                    if (rows.length == 1 && rows[0].uid == user_id) {
                        alert('Liked');
                    } else {
                        alert('Not Liked');
                    }
                });
            } 
        });
    };

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

It works on localhost and show an Alert but not on Server

Was it helpful?

Solution

You need to add your internet domain to your application sites whitelist.

  1. Go to http://developers.facebook.com
  2. Open YourApp Settings
  3. Add Platform
  4. Write your Site URL
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top