Error validating access token: Session has expired at unix time
You can have a never expiring token for your fan page. Follow the simple steps:
-
Get the admin's(i.e. yours) extended token (2 months validity). Go though the link to get the extended token. Works with perfection:
How to extend access token validity since offline_access deprecation
-
Using this token, Get the list of pages/apps-
$facebook->api("/USER_ID/accounts");
-
Get the never expiring access token for any page-
$facebook->api("/PAGE_ID?fields=access_token");
(You can use Facebook's Debug Tool to check the validity of the token.)
Fabrizio Ferrari
Updated on June 04, 2022Comments
-
Fabrizio Ferrari almost 2 years
Possible Duplicate:
Implication of Facebook offline_access deprecationI am posting this problem here because I couldn't find an answer anywhere for my specific case.
I have created a server-side PHP app that posts/showcases automatically on our FB fan page every week a link to one of our products, randomly.
This script has worked great until 10 days ago, now we get the following error when we call the script manually:
Fatal error: Uncaught OAuthException: Error validating access token: Session has expired at unix time 1355862507. The current unix time is 1356217401. thrown in /home/webadmin/virtualsheetmusic.com/html/facebook/API/base_facebook.php on line 1249
Now, I have figured out that the problem is in the passed access_token, but I can't find out how to generate a new one in the format I am using with this application.
Here is the token format we have been using so far:
$fanpagetoken = '<REMOVED ACCESS TOKEN FROM TEXT>';
And here is the PHP code we are using for posting on our wall:
#Define vars... $day = strtotime($today); $day = date("l, F j, Y", $day); $deadline = strtotime("+1 week"); $deadline = date("l, F j, Y", $deadline); // Create our Application instance (replace this with your appId and secret). $facebook = new Facebook(array( 'appId' => $appid, 'secret' => $secret, )); $attachment = array( 'access_token' => $fanpagetoken, 'message' => "Sheet Music Showcase for ".$day.":", 'name' => $headline, 'caption' => "Showcase Expiration: $deadline", 'link' => 'http://www.ourwebsite.com/s/'.$createsession, 'description' => 'View the complete high quality PDF sheet music file, listen to related audio files and more!', 'picture' => 'http://www.virtualsheetmusic.com/images/icons/new_downloadsHome/'.$mainid.'.gif', 'actions' => array(array('name' => 'Learn more...', 'link' => 'http://www.virtualsheetmusic.com/s/'.$createsession)) ); $result = $facebook->api('/oursitefanpage/feed/', 'post', $attachment);
How to generate a new token in that format?
Any help is very welcome!
Thank you in advance for any thoughts
Best, Fab.
-
Fabrizio Ferrari over 11 yearsThank you for your answer, but looks like I am having problems right at your suggested first step.
-
Fabrizio Ferrari over 11 yearsI have tried to call the extended access token with: $facebook = new Facebook(array( 'appId' => $appid, 'secret' => $secret, )); $exttk = $facebook->getExtendedAccessToken(); After adding the function to the Facebook class, but I don't get back anything inside the $exttk variable... any ideas? Thanks!
-
Sahil Mittal over 11 yearsThere must be some error in your code. Btw, you can check directly by running this in your browser: graph.facebook.com/oauth/access_token? grant_type=fb_exchange_token& client_id=APP_ID& client_secret=APP_SECRET& fb_exchange_token=SHORT_LIVED_ACCESS_TOKEN
-
Sahil Mittal over 11 yearsexchange APP_ID, APP_SECRET and SHORT_LIVED_ACCESS_TOKEN carefully!