why i cant get email with facebook login in asp.net

Last Reply on Feb 07, 2016 04:23 AM By mortkar

Posted on Feb 03, 2016 07:21 AM

Hi.

I use aspsnippets.facebookapi.dll for login into facebook in my web site. But when login into facebook, returned username and email is empty. In my facebook account, email is public. Where is my Fault.

Thank a lot.

FaceBookConnect.API_Key = "...";
                FaceBookConnect.API_Secret = "...";
                if (!IsPostBack)
                {
                    if (Request.QueryString["error"] == "access_denied")
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('User has denied access.')", true);
                        return;
                    }

                    string code = Request.QueryString["code"];
                    if (!string.IsNullOrEmpty(code))
                    {
                        string data = FaceBookConnect.Fetch(code, "me");
                        FaceBookUser faceBookUser = new JavaScriptSerializer().Deserialize<FaceBookUser>(data);
                        string Pass = faceBookUser.Id;
                        string Username = faceBookUser.UserName;
                        string Fullname = faceBookUser.Name;
                        string User_Email = faceBookUser.Email;
                    }
                }

 

Posted on Feb 07, 2016 04:23 AM

I use another way to access facebook email in asp.net and I get user email.

my code:

 script : 

<script>
        // This is called with the results from from FB.getLoginStatus().
        function statusChangeCallback(response) {
            console.log('statusChangeCallback');
            console.log(response);
            if (response.status === 'connected') {
                testAPI();
            } else if (response.status === 'not_authorized') {
                document.getElementById('MainContent_emaillbl').innerHTML = 'Please log into this app.';
            } else { document.getElementById('MainContent_emaillbl').innerHTML = 'Please log into Facebook.'; }
        }
        function checkLoginState() {
            FB.getLoginStatus(function (response) {
                statusChangeCallback(response);
            });
        }
        window.fbAsyncInit = function () {
            FB.init({
                appId: '....',
                cookie: true, 
                xfbml: true, 
                version: 'v2.2'
            });
            FB.getLoginStatus(function (response) {
                statusChangeCallback(response);
            });

        };
        (function (d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/sdk.js";
            fjs.parentNode.insertBefore(js, fjs);
        } (document, 'script', 'facebook-jssdk'));
        function testAPI() {
            FB.api('/me?fields=email', function (response) {
                document.getElementById('MainContent_emaillbl').innerHTML = 'Thanks for logging in, ' + response.email + '!';
            });
        }
    </script>

html :  

<asp:LinkButton ID="f_containerBTN" runat="server" CssClass="icon-container" OnClientClick="checkLoginState();"><i class="icon fa fa-facebook"></i></asp:LinkButton>
<asp:Label ID="emaillbl" runat="server" Text="Label"></asp:Label>

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html