title: Facebook PHP post to fan page with cronjob?
body: <p>I am using the following code to post to my facebook fan page and it is working fine. Now I want to use cronjob in order to post to Facebook. I know I have to use as access token but I am not sure how to set it up. I tried to use <code>echo</code> my own access token and the page's access token and use it in the post api but that did not work I got this error:</p>
  
  <pre><code>Uncaught OAuthException: An active access token must be used to query information about the current user.
  </code></pre>
  
  <p>Here is my code that I tried:</p>
  
  <pre><code>require_once('scripts/facebook.php');
      $config = array('appId' =&gt; 'xxx','secret' =&gt; 'xxx');
  
      $params = array('scope'=&gt;'user_likes,publish_actions,email,offline_access,publish_stream,manage_pages');
      $facebook = new Facebook($config);
      $user = $facebook-&gt;getUser();
      if($facebook-&gt;getUser()) {
      try {
  
          $user_profile = $facebook-&gt;api('/me');
          $access_token = $facebook-&gt;getAccessToken();
          //echo "1. ".$access_token;
  
        } catch(FacebookApiException $e) {
                          $login_url = $facebook-&gt;getLoginUrl($params);
                          error_log($e-&gt;getType());
                          error_log($e-&gt;getMessage());
        }   
      } else {
          $login_url = $facebook-&gt;getLoginUrl($params);
  
      }    
  
  $page_id = "xxxxxxxxxxxxx";
              $page_access_token = "";
              $result = $facebook-&gt;api("/me/accounts");
              foreach($result["data"] as $page) {
                  if($page["id"] == $page_id) {
                  $page_access_token = $page["access_token"];
                  //echo '&lt;br&gt;';
                  //echo "2. ".$page_access_token;
                  break;
                      }
                  }
  
  
          $args = array(
              'access_token'  =&gt; 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
              'message'       =&gt; stripslashes($image_caption).$animaged_gif,
              'name' =&gt; stripslashes($image_caption).$animaged_gif,
              'link' =&gt; "http://www.example.com/images.php?i=".$image_name,
              'picture' =&gt; "http://www.example.com/thumbnails/".$image_name.".png",
              'actions' =&gt; array(
              'name' =&gt; 'See Pic',
              'link' =&gt; "http://www.example.com/images.php?i=".$image_name
              )
  
          );
         $post = $facebook-&gt;api("/$page_id/feed","post",$args);
  </code></pre>
  
  <p>As you can see that I tried to use the actual access token that I got when I echo out my own access token. But that did not work. I also used the page's access token, but that also did not work. Can you please tell what I am missing here or what is the proper way to do this ?
   After some further search I did, I came across <code>setAccessToken</code> and <code>$page_info = $fb-&gt;api("/".$sInfo['pageId']."?fields=access_token");</code> but there is very limited resources on how to use them. I am not even sure if those will be appropriate to this problem. All I need to know is which access token I need to use and what is the appropriate code to set it up ?</p>