title: Facebook Login with custom button javascript sdk
body: <p>I'm using Facebook javascript sdk. I created a custom facebook button and I'm working on localhost. When I connect to Facebook I get not authorized response. Also when I click the button click function doesnt work. How can I solve this problem?</p>
  
  <blockquote>
    <p>Object {status: "not_authorized", authResponse: null}</p>
  </blockquote>
  
  <p><strong>HTML Code</strong></p>
  
  <pre><code>    &lt;div class="col-md-12 text-center"&gt;
          &lt;button class="loginBtn loginBtn--facebook" id="test"&gt;
              &lt;span&gt;Login with Facebook&lt;/span&gt;
          &lt;/button&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p><strong>JS Code</strong></p>
  
  <pre><code>function statusChangeCallback(response) {
              console.log(response);
              if (accessToken) {
                  var accessToken = response.authResponse.accessToken;
              }
              if (response.status === 'connected') {
                  testAPI2(accessToken);
              } else if (response.status === 'not_authorized') {
                  console.log("Err");
              } else {
                  console.log("Err");
              }
          }
  
          function checkLoginState() {
              FB.getLoginStatus(function (response) {
                  statusChangeCallback(response);
              });
          }
  
          window.fbAsyncInit = function () {
              FB.init({
                  appId      : '39798***',
                  cookie     : true,
                  xfbml      : true,
                  version    : 'v2.8'
              });
  
              FB.getLoginStatus(function (response) {
                  statusChangeCallback(response);
              });
          };
  
          (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_EN/sdk.js";
              fjs.parentNode.insertBefore(js, fjs);
          }(document, 'script', 'facebook-jssdk'));
  
          function testAPI2() {
              FB.api('/me', { fields: 'id,name' },
                  function (response) {
                      var user_id = response.id;//name
                      var name = response.name;
                      var type = 1;
                      $.ajax({
                          type: 'post',
                          url: "services/services.php",
                          //dataType : 'json',
                          data: {
                              type: 'facebookLogin',
                              facebookId: user_id
                          },
                          async: true,
                          cache: false,
                          success: function (data) {
                              console.log(data);
                              setTimeout(function () {
                              }, 1000);
                          },
                          error: function (data) {
                              console.log(data);
                              console.log("An error occurred");
                          }
                      });
                  }
              );
          }
  
             $("#test").click(function(){
                 checkLoginState();
             });
  </code></pre>