1

サイトにログインしたユーザーからデータを取得する方法を理解するのに苦労しています。現在、javascript SDK を使用していますが、ユーザーのデータを正しく要求する方法と、それを送信する方法を理解しようとしています。サーバー側に...次のようなものかもしれないと思いました

req.body.id 

FacebookのユーザーIDですが、それだけではないと思います...

これが私のログインページのJavaScriptコードです。

script(src='//connect.facebook.net/en_US/all.js')
div#fb-root
    script.
            window.fbAsyncInit = function() {
                // init the FB JS SDK
            FB.init({
                appId: 'blank', // App ID from the app dashboard
                //channelUrl:'//WWW.YOUR_DOMAIN.COM/channel.html', // Channel file for x-domain comms
                status     : true,                                 // Check Facebook Login status
                xfbml      : true,                                  // Look for social plugins on the page
                cookie: true
            });



        };



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


        function authUser() {
                FB.login(checkLoginStatus, {scope:'email, user_likes'});

                function checkLoginStatus(response) {
                    if(response && response.status == 'connected') {
                        alert('User is authorized');
                        document.getElementById('loginButton').style.display = 'none';
                        console.log('Access Token: ' + response.authResponse.accessToken);
                        var uid = response.authoResponse.userID;
                        var accessToken = response.authoResponse.accessToken;
            testAPI();
                        getFBData ();
                    } else {
                        alert('User is not authorized');
                        document.getElementById('loginButton').style.display = 'block';
                    }
                }


            }


        function testAPI() {
            console.log('Welcome!  Fetching your information.... ');
            FB.api('/me', function(response) {
                console.log('Good to see you, ' + response.name + '.' + response.id);
            });
        };

        function getFBData () {
            FB.api('/me', function(data){
                alert(data.first_name + data.last_name + data.id);
            })
        };
        function fbLogout() {
            FB.logout(function (response) {
                //window.location.replace("http://stackoverflow.com"); is a redirect
                window.location.reload();
            });
        }




    div.centerContent
            form(method="POST", action="/login")
                fieldset
                    legend Login
                    input(type="email", name="email", placeholder="Email", maxlength="20", value= "")   
                    br
                    input(type="password", name="password", id="password", placeholder="Password", maxlength="20", value= "")   
                    br
                    input.btn.btn-primary(type="submit", name="login", value="Login")
                    a(href="/")
                        button.btn(type="button") Cancel
            <fb:login-button show-faces="true" width="200" max-rows="1"></fb:login-button>
            button#fbLogout(type="button", onclick="fbLogout()") Logout of FB
            button#fbLogin(type="button", onclick="authUser()") Login to FB

翡翠ですが、読めるはずです。

ユーザーの情報を実際に取得する方法に関するヘルプまたは指示 (特に、プロフィール写真、アクセス トークン、ユーザー ID、姓名を探しています)

ありがとう。

編集:

バックエンドで node.js と mongodb を使用しています

4

2 に答える 2

3

コードには多くの問題があります。私が思う最大の問題は、コールバック内で応答を使用しないことです! その他は、authResponse や authResponse などの変数のスペルが間違っているだけです。

これを試して:

    function authUser() {
            FB.login(checkLoginStatus, {scope:'email, user_likes'});

            function checkLoginStatus(response) {
                if(!response || response.status !== 'connected') {
                    alert('User is not authorized');
                    document.getElementById('loginButton').style.display = 'block';
                } else {
                    alert('User is authorized');
                    document.getElementById('loginButton').style.display = 'none';
                    console.log('Access Token: ' + response.authResponse.accessToken);

                    //This has to be in your callback!
                    var uid = response.authResponse.userID;
                    var accessToken = response.authResponse.accessToken;

                    testAPI();
                    getFBData();
                }
            }
        }


    function testAPI() {
        console.log('Welcome!  Fetching your information.... ');
        FB.api('/me', function(response) {
            console.log('Good to see you, ' + response.name + '.' + response.id);
        });
    };

    function getFBData () {
        FB.api('/me', function(data){
            alert(data.first_name + data.last_name + data.id);
        })
    };
    function fbLogout() {
        FB.logout(function (response) {
            //window.location.replace("http://stackoverflow.com"); is a redirect
            window.location.reload();
        });
    }
于 2013-08-22T16:49:10.003 に答える