如何使用facebook注册并登录或连接到我的asp.net网站?

7 asp.net facebook facebook-graph-api

谁可以给我一个最好的示例网站URL,使用如何使用Facebook连接或Facebook注册到我的网站或Facebook登录与asp.net网站?

实际上我的要求是,当我通过使用Facebook注册到我的asp.net网站时,我们希望从Facebook获得facebook用户的用户名(emailid),并使用用户图像获得名字和姓氏.

Gau*_*wal 6

使用facebook javascript SDK因为使用javascript SDK你可以轻松地在facebook上做任何事情.我给你一些代码示例来做到这一点

<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<div id="fb-root">
    </div>
    <script type="text/javascript">
        FB.init({
            appId: '012341352533212',
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true, // parse XFBML
            channelUrl: 'http://www.xyz.com/channel.html', // channel.html file
            oauth: true // enable OAuth 2.0
        });
    </script>
Run Code Online (Sandbox Code Playgroud)

此代码调用您的Facebook应用程序

 <script type="text/javascript">
        function facebookLogin() {
            FB.login(function (response) {
                if (response.authResponse) {
                    FB.api('/me', function (response) {
                        jQuery('#txtFirstName').val(response.first_name);
                        jQuery('#txtLastName').val(response.last_name);
                        jQuery('#txtEmail').val(response.email);
                        jQuery('#hdfUID').val(response.id);
                        //                        FB.logout(function (response) {
                        //                        });
                    });
                } else {
                    jQuery('#txtFirstName').val('');
                    jQuery('#txtLastName').val('');
                    jQuery('#txtEmail').val('');
                    jQuery('#hdfUID').val('');
                }
            }, { scope: 'email' });
            return false;
        }
    </script>
Run Code Online (Sandbox Code Playgroud)

这个代码调用facebook的登录页面,它会回复用户ID,名字.特定用户的姓氏和电子邮件,并使用jquery将这些值保存在文本框或隐藏字段中,并在服务器端代码页上获取这些值.