title: Rails + Facebook: How to renew Facebook access token?
body: <p>In a Rails app, we have implemented Facebook API. We have a Facebook page, where we need to automatically post statuses when a user will post something to the Rails app. The problem is, that we need automatically renew Facebook access token.
  I am trying to do it this way, but as I am doing it the first time, I am a little bit lost here:</p>
  
  <pre><code>def fb_autopost    
      require 'net/http'
      temp_token = 'my_short_time_token'
  
  
      app_id = '145634995501123' # I didn't put here real token from obvious reason
      app_secret = '0dd5fcf93b4280fb19bf6b80f487c123' # I didn't put here real token from obvious reason
      puts "https://graph.facebook.com/oauth/access_token?client_id=#{app_id}&amp;client_secret=#{app_secret}&amp;grant_type=fb_exchange_token&amp;fb_exchange_token=#{temp_token}"
      puts '---'
      url = "https://graph.facebook.com/oauth/access_token?client_id=#{app_id}&amp;client_secret=#{app_secret}&amp;grant_type=fb_exchange_token&amp;fb_exchange_token=#{temp_token}"
      response = open(url)
      puts response.inspect
      puts '---'  
    end
  </code></pre>
  
  <p>When I run this code, I get this error:</p>
  
  <pre><code>Processing by ListingsController#post_to_fb as HTML
  Completed 500 Internal Server Error in 1015ms
  
  OpenURI::HTTPError (400 Bad Request):
    app/controllers/listings_controller.rb:194:in `fb_autopost'
  </code></pre>
  
  <p>I would like to ask you for help how to renew the token. Is in this case the best way to store the token in the database and like one day before expiring to run this action and renew the token?
  Or is there any better way to do that?</p>
  
  <p>Thank you so much</p>