Anandhan Anandhan - 7 days ago 5
PHP Question

Facebook Error validating access token: Session has expired at unix time

I have integrated the offline wall posting for the users of my website who have linked their FB accounts with there user details. I have stored there FB-id, FB-Access token in my database and by using the PHP-SDK libraries I had integrated the feed wall posting in the website. Everything worked very well with all users getting the messages on there facebook wall. But today all the things went in vain as it throws various kinds of error. I have been searching for more documents but can't find the exact relevant solution for this issues.

Lines of code i have used for FB-Wall Posting

$usid=$pageinfo['user']['id_facebook'];
$accestoken=$pageinfo['user']["facebook_accesstoken"];

if($pageinfo['user']['user_fbtoken']=='1')

$attachment = array(
'access_token' => $accestoken,
'message' => "myTaste || real restaurant reviews, share your taste on myTaste",
'name' => "My Favorite Restaurant is ".$business['name'].$business['location']['city']."-What is yours? ",
'link' => $business['personal_url'],
'description' => "",
'picture'=> "http://googima.com/images/mysite.gif"
);

$facebook->api("/".$usid."/feed", "post",$attachment);
}


Error messages:

Uncaught OAuthException: Error validating access token: Session has expired at unix time

Uncaught OAuthException: (#210) User not visible thrown in /hsphere/local/home/mysite.com/include/3rdparty/facebook-php-sdk/src/facebook.php


The main idea of doing this offline wall posting is user is not going to asked for the FB login each time when do some reviews in the website. It need to post automatically by using the FB details that we have stored in the user table.

Answer

Once you grant the publish_stream permission, no need for the access_token. So removing it and using something like this would work even without a valid session (just an example):

$params =  array(
    'message' => "Test Message",
    'picture'=> "http://path/to/image.jpg"
);  
$post_id = $facebook->api("/$uid/feed", "post",$params);

For more information refer to this answer (EDIT 4). Kudos to @zerkms for this info btw!