-1

I'm using Fb.login(); for login button and saving the info to the database like this.

  function testAPI() {
console.log('Welcome!  Fetching your information.... ');

FB.api('/me', function(response) {
    console.log(response);
  console.log('Successful login for: ' + response.name);
  document.getElementById('status').innerHTML =
    'Thanks for logging in, ' + response.name + '!';  

                var fname= response.first_name;
                var lname= response.last_name;
                var gender= response.gender;
                var email= response.email;
                var id= response.id;


                   $.ajax({
                   url: "save.php",
                   type: "POST",
                   dataType:'json',
                   data: {name: fname,email:email,gender:gender,id:id},
                   success: function(data){
                  console.log(data);
                  }
            });  
});

}

Above code works fine when the default button is used but not when using the custom button.

What I want to achieve is that the custom button should change the text inside the Response div and also change the like button to logged in format. What am I doing wrong here?

Rahul
  • 346
  • 1
  • 19
  • possible duplicate of [Given URL is not allowed by the Application configuration Facebook application error](http://stackoverflow.com/questions/19098952/given-url-is-not-allowed-by-the-application-configuration-facebook-application-e) – Walter Chapilliquen - wZVanG Jun 27 '15 at 05:38
  • @wZVanG That is not my concern. Would you be able to tell me why the Data is not added to the database when I use a custom button? also it does not change the like button status after logging in or the text inside responsive div. – Rahul Jun 27 '15 at 05:47

1 Answers1

0

Answering my own question.

To do this you need to subscribe to auth.login event using the following code.

FB.Event.subscribe('auth.login', function(resp) {
    //do something now.
}
Rahul
  • 346
  • 1
  • 19