1

なんらかの理由で今日、既存のメンバーの自動ログインのコードが壊れました。通常、このコードは完全に機能しますが、firebug でチェックした後、何らかの理由で「auth.login」を見つける際に問題があることがわかりました。動作していません。(手動で更新すると、メンバーは適切に接続されていると表示されます。問題は、セッションが開く前の自動ログインであり、ページの更新が必要です)また、問題が「auto.login」だけであるかどうかを確認し、それを「auth.authResponseChange」を実行すると、ページが更新され続けました...その問題は「auth.login」トリガーにあると思います。この問題を引き起こす可能性のある特別な理由、または Facebook が行った変更について誰かが知っていますか?

* update *バグが解決しました!この問題は facebook によって修正されました。

このバグは報告されており、こちらの Facebook でも回答されています。

https://developers.facebook.com/bugs/524245490930206?browse=search_50f87d9e8869a5e06191882#

ところで、これはWORKING AGAINコードです:

<div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
              appId  : '<?php =$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
        });

      // Additional initialization code here
        FB.Event.subscribe('auth.login', function(response) {
          window.location.reload();
        });
      };
      // 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#xfbml=1";
         ref.parentNode.insertBefore(js, ref);
       }(document));
    </script>
4

3 に答える 3

3

auth.login から auth.statusChange に変更し、getLoginStatus にすべてラップしたので、接続されていない場合にのみ実行され、問題なく動作しているようです。こんな感じ(window.fbAsyncInit = function() {内)

  FB.getLoginStatus(function(response) {
    if (response.status != 'connected') {
      FB.Event.subscribe('auth.statusChange', function(response) {
        if (response.authResponse) {
          // whatever code runs when user logs in
        }
      });
    }
  });
于 2013-01-21T17:53:09.327 に答える
1

私は同じ問題を経験しているようです..

数時間前まで、ユーザー (以前に私のアプリに承認してログインしていた) が私の Web サイトを開いて Cookie の有効期限が切れたとき、ログイン ボタンが表示されましたが、数秒後 (JS SDK がログイン機能)、彼は自動的にログインし、ページはログイン ボタンなしで、ユーザー情報とともに再読み込みされました。

Cookie の有効期限が切れた後に既に登録されているユーザーがサイトを開くと、ログイン ボタンが再び表示されますが、ユーザーは自動的にログインせず、以前のようにページがリロードされません。奇妙なことに、ログイン ボタンをクリックしても機能しません。ページを手動で更新すると、ログイン ボタンが消えてユーザー情報が表示されるので、実際にはユーザーがログインしているように見えますが、ページのリロードをトリガーするイベントがキャッチされませんでした。

手動でログアウトして再度ログインすると(したがってphp sdkを使用して)、すべてが機能します。

私のコード:

<script>
        window.fbAsyncInit = function() {
            FB.init({
                appId: '<?php echo $facebook->getAppID() ?>',
                cookie: true,
                xfbml: true,
                oauth: true
            });
            FB.Event.subscribe('auth.login', function(response) {
                window.location.reload();
            });
            FB.Event.subscribe('auth.logout', function(response) {
                window.location.reload();
                });
        };
        (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 facebookLogin() {
            FB.login(function(response) {
                // handle the response
            }, {scope: 'email, publish_stream, read_friendlists'});
        }
    </script>

更新js コードに次の数行を追加しました。

FB.Event.subscribe('auth.statusChange', function(response) {
                alert('The status of the session is: ' + response.status);
            });

したがって、トークンの有効期限が切れた後にユーザーが私のページを開くと、次のようになります。

  • php sdk は、彼がログインしていないことを検出し、ログイン ダイアログを表示します (以前と同様)。
  • javascript SDK がログイン機能をトリガーします (以前のように)
  • ユーザーは定期的にログインします(以前と同じように)(アラートがポップアップするため、確実に知ることができます:セッションのステータスは:接続されています)
  • しかし..イベントauth.loginはトリガーされません->スクリプトは成功したログインを認識しません->ページはリロードされません
于 2013-01-16T14:21:42.890 に答える
0

I was having the exact same problem. The javascript SDK made the users auto-login with a page reload if they connected my app and their access token had expired.

I solved it by switching to auth.statusChange instead of auth.login. Then I check with the PHP Facebook SDK if the user is logged in and if he is, i don't subscribe to the auth.statusChange event in javascript. (If you do include the auth.statusChange in javascript when the user is logged in, you will end up in an infinite page refresh loop, at least that was the case with my implementation).

于 2013-01-16T19:09:48.663 に答える