Search code examples
javascriptfacebookfacebook-authentication

Why does this simple Facebook Javascript SDK code keep failing?


I tried to use some code from the documentation, but it keeps giving me an error: An error occurred. Please try again later. What is wrong with my code?

Relevant JSFiddle: http://jsfiddle.net/AHkXS/

Relevant HTML:

    <html>
    <head>
      <title>My Facebook Login Page</title>
    </head>
    <body>
      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          FB.init({
            appId      : 'YOUR_APP_ID', //I changed this
            status     : true, 
            cookie     : true,
            xfbml      : true,
            oauth      : true,
          });
        };
        (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>
      <div class="fb-login-button" data-scope="email,user_checkins">
        Login with Facebook
      </div>
    </body>
 </html>    

Solution

  • I think whenever i ran into this problem it was because i was testing it outside of the domain in which my APP ID was valid.