Get User Details by Facebook Login Authentication

Default.aspx
  1. <script>  
  2.         // Load the SDK Asynchronously  
  3.         (function (d) {  
  4.             var js, id = 'facebook-jssdk'ref = d.getElementsByTagName('script')[0];  
  5.             if (d.getElementById(id)) { return; }  
  6.             js = d.createElement('script'); js.id = id; js.async = true;  
  7.             js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";  
  8.             ref.parentNode.insertBefore(js, ref);  
  9.         }(document));  
  10.     </script>  
  11.     <%--https://developers.facebook.com/apps/YourAppId/review-status/--%>  
  12.     <%-- Use link to check app status for live --%>  
  13.   
  14.     <script src="https://connect.facebook.net/en_US/all.js" type="text/javascript"></script>  
  1. <div>  
  2.   
  3.            <script src="http://code.jquery.com/jquery-1.8.0.min.js" type="text/javascript"></script>  
  4.   
  5.            <script>  
  6.                $("document").ready(function () {  
  7.                    // Initialize the SDK upon load  
  8.                    FB.init({  
  9.                        appId: 'YourAppId'// App ID  
  10.                        //channelUrl: '//' + window.location.hostname + '/Facebook.aspx', // Path to your Channel File  
  11.                        channelUrl: 'YourPageURL',  
  12.                        scope: 'id,name,gender,user_birthday,email'// This to get the user details back from Facebook  
  13.                        status: true// check login status  
  14.                        cookie: true// enable cookies to allow the server to access the session  
  15.                        xfbml: true  // parse XFBML  
  16.                    });  
  17.                    // listen for and handle auth.statusChange events  
  18.                    FB.Event.subscribe('auth.statusChange', OnLogin);  
  19.                });  
  20.   
  21.   
  22.                function OnLogin(response) {  
  23.                    if (response.authResponse) {  
  24.                        FB.api('/me?fields=id,name,gender,email,birthday', LoadValues);  
  25.                    }  
  26.                }  
  27.   
  28.                //This method will load the values to the labels  
  29.                function LoadValues(me) {  
  30.                    if (me.name) {  
  31.                        document.getElementById('displayname').innerHTML = me.name;  
  32.                        document.getElementById('FBId').innerHTML = me.id;  
  33.                        document.getElementById('DisplayEmail').innerHTML = me.email;  
  34.                        document.getElementById('Gender').innerHTML = me.gender;  
  35.                        document.getElementById('DOB').innerHTML = me.birthday;  
  36.                        document.getElementById('auth-loggedin').style.display = 'block';  
  37.                        var label = document.getElementById("Label1");  
  38.                        var textbox = document.getElementById("TextBox1");  
  39.   
  40.                        label.innerText = me.email;  
  41.                        //textbox.nodeValue = label.innerText;  
  42.                        document.getElementsById("TextBox1").value = me.email;  
  43.                    }  
  44.                }  
  45.            </script>  
  46.   
  47.        </div>  
  48.        <div id="fb-root">  
  49.        </div>  
  50.        <!-- This initializes the FB controls-->  
  51.        <div class="fb-login-button" autologoutlink="true" scope="user_birthday,email">  
  52.            Login with Facebook  
  53.        </div>  
  54.        <!-- FB Login Button -->  
  55.        <!-- Details -->  
  56.        <div id="auth-status">  
  57.            <div id="auth-loggedin" style="display: none">  
  58.                Hi, <span id="displayname"></span>  
  59.                <br />  
  60.                Your Facebook ID : <span id="FBId"></span>  
  61.                <br />  
  62.                Your Email : <span id="DisplayEmail"></span>  
  63.                <br />  
  64.                Your Sex: <span id="Gender"></span>  
  65.                <br />  
  66.                Your Date of Birth : <span id="DOB"></span>  
  67.                <br />  
  68.                <asp:Label ID="Label1" runat="server"></asp:Label><br />  
  69.                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
  70.            </div>  
  71.        </div>