title: How to build a script that auto-post on my Facebook Pages with a non-permanent Access Token?
body: <p>I'm developing a ruby script that push every new content on my Facebook Page as a post.
  I know about that the access token will expire in two hours, so how I could do that?</p>
  
  <p>Now this piece of code works because I set "user_access_token" manually (But after 2 hours it expire). It's my company facebook page linked to my facebook app.
  Should I click every two hours on "Facebook connect" and grant a new access token??</p>
  
  <pre><code>@user_graph = Koala::Facebook::API.new(user_access_token)
  pages = @user_graph.get_connections('me', 'accounts')
  # get access token for first page
  first_page_token = pages.first['access_token']
  
  # or: retrieve access_token for a given page_id
  page_token = @user_graph.get_page_access_token(page_id)
  @page_graph = Koala::Facebook::API.new(page_token)
  
  @page_graph.put_wall_post('post on page wall') # post as page, requires publish_stream permission
  </code></pre>
  
  <p>I have got "Page Access Token" from here</p>
  
  <p><img src="https://i.stack.imgur.com/HElxt.png" alt="I got PAGE ACCESS TOKEN FROM HERE"></p>
  
  <p>but in one hour it will expire</p>
  
  <p><img src="https://i.stack.imgur.com/0htvq.png" alt="enter image description here"></p>
  
  <p><strong>[RESOLVED]</strong></p>
  
  <p>To get an extended Page Access Token, exchange the User Access Token for a long-lived one and then request the Page token. This "extended" token for Pages will actually not have any expiry time.</p>
  
  <p><a href="https://developers.facebook.com/docs/howtos/login/extending-tokens/#step1" rel="nofollow noreferrer">https://developers.facebook.com/docs/howtos/login/extending-tokens/#step1</a></p>
  
  <p>I have resolved executing a curl request, and saving "Page access token" in my code manually</p>