Using facebook login for my site

I am trying to include a facebook login button on my home page. I linked it to my application, so I have the application id and secret, but I can't figure out how to check if a user is logged in to my site, so in my database to view his custom file. I used the javaScript sdk from facebook, but when I click the facebook login button, after login, nothing happens and my site home page is displayed again. Does anyone know how to get the user's email address from the javascript sdk? I am using Java Servlets for my pages. I used code from facebook documentation.

<div id="fb-root"></div>
  window.fbAsyncInit = function() {
      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
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); = id; js.async = true;
     js.src = "//";
     ref.parentNode.insertBefore(js, ref);

<div class="fb-login-button" data-scope="email">



source to share

2 answers

Client flow

The client side thread also uses the OAuth Dialog for user authorization and application authorization. The only difference is that you must specify a parameter response_type

with a token value:


Just like server side stream, you can also request additional permissions using the scope parameter:


This may be possible, but this is not the best practice. I would suggest introducing some server side scripts (like PHP), but if you are using the Facebook Javascript SDK only to fetch some user data, this method might be helpful. The workflow will be like this.

  • The user clicks the Facebook Connect button, which is redirected to: ? client_id = YOUR_APP_ID & redirect_uri = YOUR_URL & response_type = token

  • Facebook checks YOUR_APP_ID and url and authenticates

  • Redirecting to your URL.



... with an access token in the URL.

Later, you extracted the token from the url and used it to execute FQL (Facebook Query Language) with an AJAX request and get user data.

Described here:



After redirecting and OAuth authorization, once the page is shown again, try resetting the session (something similar to print_r ($ _ SESSION) in php). It should contain user data retrieved from facebook.



All Articles