Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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.
 

<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 29-Apr-13 20:31pm
Edited 30-Apr-13 0:05am
v3
Comments
Tadit Dash at 4-Jun-14 10:13am
   
Does your app have all permissions to access the User Details?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
v2
Comments
sonusharma65 at 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
kkakadiya at 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.
kkakadiya at 30-Apr-13 7:24am
   
i have just checked it and it is working on fb login i can access/redirect to other pages..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can retrive all information using JSon object like:-
 
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);
  Permalink  

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

  Print Answers RSS
0 Marcin Kozub 310
1 OriginalGriff 248
2 Sergey Alexandrovich Kryukov 215
3 Richard MacCutchan 202
4 Praneet Nadkar 197
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 4 Jun 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100