Expend access token for fan pages-Collection of common programming errors

i searched for 2 days about my problem find a lot of solution but none worked for me. I want to make a facebook application that i will access from cronjob once for 20 minutes. This app shoult post to my page a photo with description in a album. The problem is the token access that expires … so the code …

//connect to api
$facebook = new Facebook(array(
          'appId'  => APP_ID,
          'secret' => APP_SECRET
        ));

//get the page token
$page_id = 222506244512259;
$page_info = $facebook->api("/$page_id?fields=access_token");

$page_info['access_token']; //so if i use this token is ok but it expires in 2 hours

//now we try to use something else to extend the time

$token_url="https://graph.facebook.com/oauth/access_token?client_id=".APP_ID."&client_secret=".APP_SECRET."&grant_type=fb_exchange_token&fb_exchange_token=".$facebook->getAccessToken();

//so if i use this formula i will receive a token that never expires, is ok but if I try to use the acces token for posting it doesn work is not valid

$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$page_info['access_token'] = $params['access_token'];


//and this is the rest code for posting

$image['file'] = 'images/rezultate/'.$link;
$args = array( 'access_token' => $page_info['access_token'], 'message' => ':-)

Originally posted 2013-11-27 11:53:31.