title: Rails - Facebook with Omniauth and Koala: How to renew an expired token
body: <p>I have an application where users can link their Facebook accounts.  They can log in using their email, but they can link their Facebook account.</p>
  
  <p>In the view where I show the linked social networks (Facebook and others), I have something like this:</p>
  
  <pre><code>&lt;%= image_tag @facebook.get_facebook_picture %&gt;
  </code></pre>
  
  <p>This will call an instance method like this:</p>
  
  <pre><code>def get_facebook_picture
      unless self.token.nil?
        facebook_graph = Koala::Facebook::GraphAPI.new(self.token)
        fb_picture = facebook_graph.get_picture("me", { :type =&gt; "small" })
      end
  end
  </code></pre>
  
  <p>This will work well unless the Facebook token that I have stored in my DB is expired. So I have added this exception handler in the mentioned controller:</p>
  
  <pre><code>def facebook_exception_handler exception
      if exception.fb_error_type.eql? 'OAuthException'
        # Let's get a new auth token... How?
      else
        logger.debug "Damn it. We don't know what error is coming from FB"
        raise exception
      end
  end
  </code></pre>
  
  <p>I catch the exception correctly, but I fail to see how would I renew the access token that I have in my database. Notice that the access token that I have has been inserted using OmniAuth. So my question is:</p>
  
  <p>Given that I have an <code>OAuthException</code>, how can I renew the access token of a particular user (UID) using <strong>Omniauth</strong>?</p>