在我的网络应用程序中使用Facebook登录 [英] Login with facebook in my web application

查看:66
本文介绍了在我的网络应用程序中使用Facebook登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过facebook登录功能。我已经完成了所有必要的步骤,但现在问题是我只能通过facebook访问登录用户的名字,现在我想在我的代码中检索下面提到的所有信息。





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>







此代码工作正常,但只提供登录用户的名称而不是其他信息,如email,dob等。我可以做什么。请帮助我使用正确的代码。




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.

推荐答案

(#auth-logoutlink)。click(function(){FB.logout(function(){window.location .reload();});});
}
< / script >
< h1 >
Facebook登录验证示例< / h1 >
< 表格 < span class =code-attribute> id = form1 runat = server >
< div & gt;
< div id = auth-status >
< div id = auth-loggedout >
< div class = fb-login-button autologoutlink = false 范围 = email,user_birthday >
使用Facebook登录< / div >
< span class =code-keyword>< / div >
< div id = auth-loggedin 样式 = display:none >
名称:< span id = auth_displayname runat = 服务器 > < / span > < a href = id = auth-logoutlink > ; 注销< / a > < br / >
电子邮件:< span id = 电子邮件 runat = server > < / span >
< br / >
个人资料图片:
< img id = profileImg < span class =code-attribute> alt = runat = server / < span class =code-keyword>> < br / > ;
D.O.B. :
< asp:Literal ID = DOB_User < span class =code-attribute> runat = server > < / asp:Literal > < br / >
城市:
< asp:Literal ID = 城市 runat = server > < / asp:Literal >
性别:
< asp:Literal ID = Gender_User runat = server > < / asp:Literal >
< / div > ;
< asp:ImageButton ID = ImageButton1 ImageUrl = 〜/ Admin / images / face1.gif runat = server

< span class =code-attribute> OnClientClick = login() / > ; < / div >
< / div > ;
< / m >
< / body >
("#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>







此代码工作正常,但只提供登录用户的名称而不是其他信息,如email,dob等。我可以做什么。请帮我提供正确的密码。




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.


您好,



查看以下链接可能会对您有所帮助:



http:// devtacular .com / articles / bkonrad / how-to-use-the-facebook-developer-toolkit-20 / [ ^ ]



http://www.aspdotnet-suresh.com/2012/04/aspnet-integrate-facebook- login.html [ ^ ]



谢谢,

kk
Hi,

check out below link might help you:

http://devtacular.com/articles/bkonrad/how-to-use-the-facebook-developer-toolkit-20/[^]

http://www.aspdotnet-suresh.com/2012/04/aspnet-integrate-facebook-login.html[^]

thanks,
kk


您可以检索所有信息使用JSon对象,如: -



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);


这篇关于在我的网络应用程序中使用Facebook登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆