4版中获取名字和姓氏

4版中获取名字和姓氏

本文介绍了如何从Facebook集成应用程序2.4版中获取名字和姓氏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html>
<head>
    <title>Facebook Login JavaScript Example</title>
    <meta charset="UTF-8">
</head>
<body>
    <script>

        function statusChangeCallback(response) {
            console.log('statusChangeCallback');
            console.log(response);

            if (response.status === 'connected') {

                testAPI();
            } else if (response.status === 'not_authorized') {

                document.getElementById('status').innerHTML = 'Please log ' +
                  'into this app.';
            } else {

                document.getElementById('status').innerHTML = 'Please log ' +
                  'into Facebook.';
            }
        }


        function checkLoginState() {
            FB.getLoginStatus(function (response) {
                statusChangeCallback(response);
            });
        }

        window.fbAsyncInit = function () {
            FB.init({
                appId: 'app_key',
                cookie: true,

                xfbml: true,
                version: 'v2.4'             });



            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() {
            console.log('Welcome!  Fetching your information.... ');
            FB.api('/me', function (response) {
                console.log('Successful login for: ' + response.name);
                document.getElementById('status').innerHTML =
                  'Thanks for logging in, ' + response.name + '!';
                $('#fName').val(response.first_name);
                $('#lName').val(response.lastst_name);
            });
        }
    </script>


    <fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
    </fb:login-button>

    <div id="status">

    </div>
    First  Name:   <label id="fName"></label>
    Last  Name:   <label id="lName"></label>
</body>
</html>

推荐答案




这篇关于如何从Facebook集成应用程序2.4版中获取名字和姓氏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 21:15