从FB到Asp.Net获取City和About Me信息

时间:2013-05-13 10:25:01

标签: asp.net facebook facebook-javascript-sdk

我已经在我的asp.net项目中获取用户个人资料信息,包括用户名,生日,电子邮件,个人资料图片和性别,现在我想获得城市和我的详细信息,我尝试了同样的方式来获取这些但不幸的是我无法做到。

我按照此link查看扩展配置文件权限,但仍然无法执行此操作。

这是我的剧本

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <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: '155578484623690', // App ID
                channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
                scope: 'id,name,gender,user_birthday,email,user_about_me,user_location',
                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) {
                        if (me.name) {
                            document.getElementById('txtDisplayName').innerHTML = me.name;
                            document.getElementById('Email').innerHTML = me.email;
                            document.getElementById('BD').innerHTML = me.birthday;
                            document.getElementById('profileImg').src = uid;
                            document.getElementById('Gender').innerHTML = me.gender;
                            document.getElementById('city').innerHTML = me.about;
                            document.getElementById('city').innerHTML = me.location;
                        }
                    })
                    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>

1 个答案:

答案 0 :(得分:0)

根据documentation关于用户,

  • 用户没有类似about的字段,而是用于Page对象。对于用户,您可能需要的字段是bio

  • 其次,location字段还包含该位置的idname。因此,您不想使用me.location而是使用me.location.name作为用户位置的名称