Search code examples
facebookxfbml

Check if user machine can access Facebook


Facebook is banned in our country. However there are still a considerable amount of users who can work around to use Facebook. Of course, many others can't. My site uses Facebook like button and like box. If the user machine cannot access Facebook, there will be some "ugly" parts on the page, where there should be Facebook plugin.

Does anyone know how to resolve this issue? I mean how to check if the user machine can access Facebook? Any trick is appreciated.


Solution

  • I managed to achieve this by using Facebook API. Just initiate a query, and call FB.XFBML.parse(); when the query completes.

    <script type="text/javascript"> 
     window.fbAsyncInit = function () {
     FB.init({
     appId: 'app id',
     status: false,
     cookie: true,
     xfbml: false,
     oauth: false
     });
     FB.api({
     method: 'fql.query',
     query: 'SELECT uid,name FROM user WHERE uid=1234'
     },
     function (response) {
     if (response[0].uid == '1234') { // Now that the user can connect to facebook
     FB.XFBML.parse();
     }
     });
     };
     (function() {
     var e = document.createElement('script');
     e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
     e.async = true;
     document.getElementById('fb-root').appendChild(e);
     }()); 
    </script>