1

セットアップしました

<div id="fb-root"></div><div class="fb-login-button" data-show-faces="true" data-width="400" data-max-rows="1" scope="email, publish_stream"></div><script type="text/javascript">
window.fbAsyncInit = function () {
    FB.init({
        appId: 'xxx', // App ID
        status: true, // check login status
        cookie: true, // enable cookies to allow the server to access the session
        xfbml: true,  // parse XFBML,
        oauth : true
    });

    FB.Event.subscribe('auth.authResponseChange', function (response) {
        if (response.status === 'connected') {
            // the user is logged in and has authenticated your
            // app, and response.authResponse supplies
            // the user's ID, a valid access token, a signed
            // request, and the time the access token 
            // and signed request each expire
            var uid = response.authResponse.userID;
            var accessToken = response.authResponse.accessToken;

            // TODO: Handle the access token

            $.post('/facebook/login', { accessToken: accessToken }, function (response) { if(response) {alert('Logged in')} });

        } else if (response.status === 'not_authorized') {
            // the user is logged in to Facebook, 
            // but has not authenticated your app
        } else {
            // the user isn't logged in to Facebook.
        }
    });


};

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

問題は、ユーザーが[ログイン]ボタンをクリックして[アプリを受け入れる]をクリックすると、ログインダイアログが閉じてイベントが発生しないため、F5キーを押さない限り投稿$ .post('/ facebook / login')も発生しないことです。

ログインダイアログボックスを閉じた直後にイベントを発生させるにはどうすればよいですか?

4

2 に答える 2

0

共有するだけです。Facebook のドキュメントを読んで答えを見つけながら、考えられる解決策を見つけてください。

http://facebook.stackoverflow.com/questions/3548493/how-to-detect-when-facebooks-fb-init-is-complete

fbEnsureInit(); 内で $.post('/facebook/login') を実行できます。<-- serg の回答を参照。

インターバル コールバックを使用してログイン ステータスを確認する方法が考えられます。

于 2012-05-13T03:51:18.650 に答える
-1

次のコマンドでページをリロードできます。F5window.location.reload();キーを押す必要はありません。

FB.loginの例:

FB.login(function(response) {
    if (response.authResponse) {
        console.log('Application authorized.');
        window.location.reload();
    } else {
        console.log('You cancelled login or you did not fully authorize the app.');
    }
}, { scope: 'email' });

または、サブスクライブイベントを使用できます。

FB.Event.subscribe('auth.authResponseChange', function(response) {
    console.log('The status of the session changed to: '+response.status);
    window.location.reload();
});
于 2012-05-13T06:33:07.340 に答える