Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using facebook login for my website

I am trying to incorporate the facebook login button into my website's homepage. I have connected it with an app, so i have the app id and secret, but i can't figure out how to check if the user is already registered to my site, so in my database, in order to preview his userprofile. I have used the javaScript sdk from facebook but when i press the facebook's login button, after the authorization, nothing happens and my website's homepage is shown again. Does anyone know how to get the user's email from the javascript sdk? I am using java servlets for my pages. I have used the code from the facebook documentation.

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '8568345835', // App ID
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>

<div class="fb-login-button" data-scope="email">
like image 389
Sokratis Staboglis Avatar asked Dec 08 '25 07:12

Sokratis Staboglis


1 Answers

After OAuth redirect and authorization, once you page is shown again, try dumping your session (something that would resemble print_r($_SESSION) in php). It should contain user data obtained from facebook.

like image 174
Ivan Avatar answered Dec 12 '25 12:12

Ivan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!