1

コアラジェムを使用してログアウトする際に問題が発生し、それらが関連しているかどうか疑問に思っています。

以下は私のJavascriptコードです:

  <script>
    window.fbAsyncInit = function() {
      FB.init({
        appId      : '310521258992725', // App ID
        channelUrl : '//localhost:3000/channel', // Channel File
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true  // parse XFBML
      });
      // Additional initialization code here
      // whenever the user logs in, we refresh the page

      FB.Event.subscribe('auth.login', function() {
        setTimeout('document.location.reload()',0);
      });

      FB.logout(function(response) {
        FB.Auth.setAuthResponse(null, 'unknown');
        setTimeout('document.location.reload()',0);
      });
    };


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

以下は私のFacebookタグです:

 <div id="fb-root"></div>

私のログアウトコード:

<a href="/" onclick="FB.logout();">Logout</a>

ログインは完全に機能し、API呼び出しを問題なく実行できます。ただし、ログアウトすると、次のエラーが発生します。

OAuthException: Error validating access token: The session is invalid because the user logged out.  app/controllers/application_controller.rb:58: in 'fbookinvite_check'

以下は私のfbookinvite_checkコードです:

  def fbookinvite_check
    unless @facebook_cookies.nil?
      @access_token = @facebook_cookies["access_token"]
      @graph = Koala::Facebook::GraphAPI.new(@access_token)
      if !@graph.nil? == true
        @friends = @graph.get_object("/me/friends")
      end
    end
  end

問題は、Cookieがアクセストークンが無効になっていることであり、リダイレクト後に@graphがnilとして表示されないことであると思われます。更新するとページは問題なく読み込まれますが、ログアウトするとエラーが発生します。

おそらく、アプリケーションをシャットダウンせずに@graph.get_objectエラーをキャッチする方法はありますか?

どんな提案でも大歓迎です!!

4

1 に答える 1

1

fbookinvite_checkはい、レスキュー元の begin/rescue でラップしてからOAuthException、アプリケーションに適切なものを返すだけです。

あなたはあなた自身の質問に答えました:

おそらく、アプリケーションをシャットダウンせずに @graph.get_object エラーをキャッチする方法はありますか?

次のように、ロジックを begin/rescue ブロックにラップします。

def fbookinvite_check
  begin
    unless @facebook_cookies.nil?
      @access_token = @facebook_cookies["access_token"]
      @graph = Koala::Facebook::GraphAPI.new(@access_token)
      if !@graph.nil? == true
        @friends = @graph.get_object("/me/friends")
      end
    end
  rescue OAuthException => ex
    # handle the exception if you need to, or just ignore it if thats ok too
  end
end
于 2012-08-15T21:13:52.703 に答える