How to extract Facebook Access token Expiration Info

zearth picture zearth · Feb 10, 2012 · Viewed 13.2k times · Source

is there ay way to get the Expiration date of the access token, I need this so I can refresh my session, also I want this way so I can avoid to look up on facebook user data when being fetch via PHP cURL.

also on this link https://developers.facebook.com/tools/access_token/ if I click the DEBUG button in one of my custom app, I can see this info (for example)

App ID: 23131XX0000123 : My Custom App
User ID: XX99858XX : Mario Bro
Issued: XX11111XX : 2:00 pm Feb 10 2012
Expires: XX11111XX : 3:00 pm Feb 10 2012
Valid:  True
Origin: Unknown
Scopes: email user_likes

and it display the expiration date from that app. Is there a way I can get that info in PHP SDK or in a graph URL command?

Answer

Juicy Scripter picture Juicy Scripter · Feb 11, 2012

Update:
The code bellow is no longer works (see bug report PHP SDK getSignedRequest does not include "expires" field) and there is no way to get that data with PHP-SDK).

You can use Debug tool to manually discover when your access_token expires.

You can get expiration time of the access_token from signed_request:

$facebook = new Facebook(array(
  'appId'=>APP_ID,
  'secret'=>APP_SECRET
));
$signedRequest = $facebook->getSignedRequest();
$expiresDate = date('c', $signedRequest['expires']);
print_r($expiresDate);