Login problems using facebook sdk

Asked

Viewed 663 times

1

I use the default facebook login sdk, where the documentation can be accessed here.

(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/pt_BR/sdk.js";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function fb_login() {
  FB.init({
    appId: '',
    cookie: true,
    xfbml: true,
    version: 'v2.8'
  });

  FB.getLoginStatus(function(response) {
    statusChangeCallback(response);
  });

  function statusChangeCallback(response) {
    if (response.status === 'connected') {
      getUserInfo();
    }
  }

  function getUserInfo() {
    FB.api('/me?fields=name,email,gender,birthday,link', function(response) {
      var data = [];
      data.push({
        name: 'token',
        value: jQuery("#token").val()
      });
      jQuery.ajax({
        url: "/api/user/create/",
        type: "POST",
        data: data,
        success: function(returnjson) {
          alert("ok");
        },
        error: function(returnjson) {
          alert("erro");
        }
      });
    });
  }
}

The problem is that I would like to use a custom button.

<div class="customBtn btn btn-block loginBtn loginBtn--facebook">
  <fb:login-button scope="public_profile,email" onclick="fb_login()">Entrar com Facebook</fb:login-button>
</div>

inserir a descrição da imagem aqui

With this by clicking the button the first time,

  • If the user is disconnected from facebook, theoretically he should call the popup window and request login to be able to pull the information to my system.
  • If the user is connected on facebook, it pulls the information to my system.

The problem is that by clicking the button, it creates the context of the facebook button inside an iframe and renders inside my button:

inserir a descrição da imagem aqui

If the user clicks again on the button inside my button (something half Inception) popup window, or pull information....

  • <fb:login-button is from some template engine you are using?

  • Nope, at first I used to <button class="btn btn-block loginBtn loginBtn--facebook" onclick="fb_login()">Entrar com Facebook</button>, but I noticed that the iframe and the popup was only created if I used <fb:login-button.

  • that is, if it is from a template engine, it is from the sdk itself //connect.facebook.net/pt_BR/sdk.js

  • That’s right @Marcelobonifazio. You own a div like this: <div id="fb-root"></div>?

  • no, I tried to adapt <div id="fb-root"></div> my need, but I found it difficult to try another route: http://www.devils-heaven.com/facebook-javascript-sdk-login/

  • I was able to adapt to my need, I will post the answer tomorrow, but if someone can answer before I give the vote

  • Cool @Marcelobonifazio. Yes, if someone has the same problem :)

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.