Click here to Skip to main content
15,889,482 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want functionality login with facebook. I have completed all necessary steps for this but now problem is i only able to access name of logged user via facebook, now i want to retrive all information mentioned below in my code.


XML
<head runat="server">
    <title>Login With Facebook</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
    <script>
        // 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));

        // Init the SDK upon load
        window.fbAsyncInit = function () {
            FB.init({
                appId: 'xxxxxxxxxxxxxxxxxx', // Your App ID
                channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
                status: true, // check login status
                cookie: true, // enable cookies to allow the server to access the session
                xfbml: true  // parse XFBML
            });

            // listen for and handle auth.statusChange events
            FB.Event.subscribe('auth.statusChange', function (response) {
                if (response.authResponse) {
                    // user has auth'd your app and is logged into Facebook
                    var uid = "http://graph.facebook.com/" + response.authResponse.userID + "/picture";
                    FB.api('/me', function (me) {
                        document.getElementById('auth_displayname').innerHTML = me.name;
                        document.getElementById('Email').innerHTML = me.email;
                        document.getElementById('profileImg').src = uid;
                        document.getElementById('DOB_User').innerHTML = me.birthday;
                        document.getElementById('City').innerHTML = response.authResponse.userID;
                        document.getElementById('Gender_User').innerHTML = me.gender;
                    })
                    document.getElementById('auth-loggedout').style.display = 'none';
                    document.getElementById('auth-loggedin').style.display = 'block';

                } else {
                    // user has not auth'd your app, or is not logged into Facebook
                    document.getElementById('auth-loggedout').style.display = 'block';
                    document.getElementById('auth-loggedin').style.display = 'none';
                }
            });
            $("#auth-logoutlink").click(function () { FB.logout(function () { window.location.reload(); }); });
        }
    </script>
    <h1>
        Facebook Login Authentication Example</h1>
    <form id="form1" runat="server">
    <div>
        <div id="auth-status">
            <div id="auth-loggedout">
                <div class="fb-login-button" autologoutlink="false" scope="email,user_birthday">
                    Login with Facebook</div>
            </div>
            <div id="auth-loggedin" style="display: none">
                Name: <span id="auth_displayname" runat="server"></span>(<a href="#" id="auth-logoutlink">logout</a>)<br />
                Email: <span id="Email" runat="server"></span>
                <br />
                Profile Image:
                <img id="profileImg"  alt="" runat="server"/><br />
                D.O.B. :
                <asp:Literal ID="DOB_User" runat="server"></asp:Literal><br />
                City :
                <asp:Literal ID="City" runat="server"></asp:Literal>
                Gender :
                <asp:Literal ID="Gender_User" runat="server"></asp:Literal>
            </div>
            <asp:ImageButton ID="ImageButton1" ImageUrl="~/Admin/images/face1.gif" runat="server"
                OnClientClick="login()" />        </div>
    </div>
    </form>
</body>



This code work fine but provide only the name of logged in user not other informations like email, dob etc. Sowhat can i do. Please help me with proper code.
Posted
Updated 29-Apr-13 23:05pm
v3
Comments
Does your app have all permissions to access the User Details?

 
Share this answer
 
v2
Comments
sonusharma65 30-Apr-13 7:06am    
Hi..kk
I have successfully logged in using "Login with facebook" but there is one issue in my mind that is :
If the user is not registered with my web application and have an account on facebook, when he tries to login with facebook at my website without having any account on it then what will happen or how should i manage it.
AND
if user is registered at both(in my web site and on facebook) then when he tries to login with facebook i want to create a session for that user to access another pages, How can i code for this...
Please help me
Thanks
Sunil sharma
kk2014 30-Apr-13 7:19am    
Hi sonu,

till i have faced this type of situations, if user have not registered in your site then we are providing facility to login with facebook account.right nw u are doing that by signing with fb acc successfully.right.
AND
if user have account in both sites then still user can access other pages.
kk2014 30-Apr-13 7:24am    
i have just checked it and it is working on fb login i can access/redirect to other pages..
You can retrive all information using JSon object like:-

SQL
ComputerBeacon.Facebook.Models.User fbUser = new ComputerBeacon.Facebook.Models.User("me", objWebContext.Session.AccessToken);

JsonArray JA = Api.Fql("SELECT uid, name, pic_square, profile_url, email FROM user WHERE uid = UserId, objWebContext.Session.AccessToken);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900