title: Facebook Koala Gem - Logging Out
body: <p>I'm having issues logging out using the Koala Gem, and wondering whether they're related.</p>
  
  <p>Below is my Javascript code:</p>
  
  <pre><code>  &lt;script&gt;
      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));
    &lt;/script&gt;
  </code></pre>
  
  <p>Below is my Facebook tag:</p>
  
  <pre><code> &lt;div id="fb-root"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>My logout code:</p>
  
  <pre><code>&lt;a href="/" onclick="FB.logout();"&gt;Logout&lt;/a&gt;
  </code></pre>
  
  <p>The login works perfectly and I can execute api calls no problem.  However, after I logout, I get the following error:</p>
  
  <pre><code>OAuthException: Error validating access token: The session is invalid because the user logged out.  app/controllers/application_controller.rb:58: in 'fbookinvite_check'
  </code></pre>
  
  <p>Below is my fbookinvite_check code:</p>
  
  <pre><code>  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
  </code></pre>
  
  <p>The problem seems to be that the cookie is that the access token is invalidated, @graph is not showing as nil after the redirect.  If I refresh, then the page loads no problem, but I get the error when I log out.</p>
  
  <p>Perhaps there's a way to catch the @graph.get_object error without shutting down the application?</p>
  
  <p>Any suggestions would be greatly appreciated!!  </p>