title: Facebook API offline access
body: <p>I have a script I'd like to run via a cron job:</p>
  
  <pre><code>&lt;?
  
  require_once 'fb_access.php';
  
  $user = $facebook-&gt;getUser();
  
      if ($user) {
        try {
          $page_id = '********';
          $page_info = $facebook-&gt;api("/$page_id?fields=access_token");
          if( !empty($page_info['access_token']) ) {
              $args = array(
                  'access_token'  =&gt;  $page_info['access_token'],
                  'message'       =&gt;  'This is the message',
                  'link'          =&gt;  'http://thisisthelink',
                  'caption'       =&gt;  'This is the caption',
                  'description'   =&gt;  'This is the description',
              );
              $post_id = $facebook-&gt;api("/$page_id/feed","post",$args);
          }
        } catch (FacebookApiException $e) {
          error_log($e);
          $user = null;
        }
      }
     ?&gt;
  </code></pre>
  
  <p>However when I try to run it via the cron job, it doesn't work.  I've figured out this has something to do with the offline_access token.  But from what I've read, a user must manually login to get the token.  As I'd like to run this via a cron job, that's not feasible.  Any ideas?</p>
  
  <p>UPDATE:</p>
  
  <p>I tried this; is it completely wrong?</p>
  
  <pre><code>require_once 'fb_access.php';
  
  $user = $facebook-&gt;getUser();
  $token = $facebook-&gt;getAccessToken();
  
  if ($user) {
      try {
          $page_id = '**********';
          $args = array(
              'access_token'  =&gt;  $token,
              'message'       =&gt;  'This is the message',
              'link'          =&gt;  'http://thisisthelink',
              'caption'       =&gt;  'This is the caption',
              'description'   =&gt;  'This is the description',
          );
      $post_id = $facebook-&gt;api("/$page_id/feed","post",$args);
      }
      catch (FacebookApiException $e) {
          error_log($e);
          $user = null;
      }
  }
  </code></pre>
  
  <p>UPDATE #2:</p>
  
  <pre><code>&lt;?php
  
  require_once 'fb_access.php';
  
  $user = $facebook-&gt;getUser();
  $token = '*******LONG_ACCESS_TOKEN*******';
  
  $page_id = '**********';
  $args = array(
      'access_token'  =&gt;  $token,
      'message'       =&gt;  'This is the message',
      'link'          =&gt;  'http://www.thisisthelink.com',
      'caption'       =&gt;  'This is the caption',
      'description'   =&gt;  'This is the description',
  );
  
  $post_id = $facebook-&gt;api("/$page_id/feed","post",$args);
  
  ?&gt;
  </code></pre>
  
  <p>Using this I get: Fatal error: <code>Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action thrown in /base_facebook.php on line 1106</code></p>