0

我正在使用 facebook javascript SDK 注册用户并将其登录到我的站点。登录工作正常。

但是,我想将数据存储到 mysql 中,但每次我在控制台日志中出现“$ 未定义”的错误。经过数小时的尝试和搜索,我无法理解

  1. 我在这里做错了什么?

  2. 我可以使用相同的代码来验证 facebook 画布应用程序吗?

我正在学习使用 fb 身份验证。请帮助我。

    <script type="text/javascript">
     var button;
     var userInfo;

    window.fbAsyncInit = function () {
    FB.init({ appId:'abccccc', //change the appId to your appId
    status:true,
    cookie:true,
    xfbml:true,
    oauth:true});

showLoader(true);

function updateButton(response) {
    button = document.getElementById('fb-auth');
    userInfo = document.getElementById('user-info');

    if (response.authResponse) {
        register();

        FB.api('/me?', function (info) {
            login(response, info);

        });


        button.onclick = function () {
            FB.logout(function (response) {
                logout(response);
            });
        };

    } else {
        //user is not connected to your app or logged out
        button.innerHTML = 'Login';
        button.onclick = function () {
            showLoader(true);
            FB.login(function (response) {
                if (response.authResponse) {
                    FB.api('/me', function (info) {
                        login(response, info);
                    });
                } else {
                    //user cancelled login or did not grant authorization
                    showLoader(false);
                }
            }, {scope:'email,user_birthday,status_update,publish_stream,user_about_me'});
        }
    }

}

function register() {

    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function (response) {

        console.log('Good to see you, ' + response.name + '.' + ' Email: ' + response.email + ' Facebook ID: ' + response.id);


    });
    $.post('send.php', { option:'fb_register', name:response.name, email:response.email}, function (data) {
        alert('registerd')
    });

}

// run once with current status and whenever the status changes
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
};
(function () {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol
        + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
 }());


 function login(response, info) {
 if (response.authResponse) {
    var accessToken = response.authResponse.accessToken;

    userInfo.innerHTML = '<img src="https://graph.facebook.com/' + info.id + '/picture">' + info.name
            + "<br /> Your Access Token: " + accessToken;
    button.innerHTML = 'Logout';
    showLoader(false);
    document.getElementById('other').style.display = "block";
   }
  }

function logout(response) {
userInfo.innerHTML = "";
document.getElementById('debug').innerHTML = "";
document.getElementById('other').style.display = "none";
showLoader(false);
}

 //stream publish method
 function streamPublish(name, description, hrefTitle, hrefLink, userPrompt) {
showLoader(true);
FB.ui(
        {
            method:'stream.publish',
            message:'',
            attachment:{
                name:name,
                caption:'',
                description:(description),
                href:hrefLink
            },
            action_links:[
                { text:hrefTitle, href:hrefLink }
            ],
            user_prompt_message:userPrompt
        },
        function (response) {
            showLoader(false);
        });

}
function showStream() {
FB.api('/me', function (response) {
    //console.log(response.id);
    streamPublish(response.name, 'I like the articles of Thinkdiff.net', 'hrefTitle', 'http://thinkdiff.net', "Share thinkdiff.net");
});
 }
</script>
4

1 回答 1

1

您的函数register正在调用一个函数$.post,大概来自 jQuery。如果您没有加载任何定义的内容$,它将不会被定义,因此调用$.post将失败。

我建议加载 jQuery,它提供$.post.

于 2013-04-15T05:26:32.980 回答