How to extract Facebook Access token Expiration Info
Solution 1
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);
Solution 2
There is a Graph API endpoint (may have been released after this question) that gives you the expiration time and other useful information. See the Debugging Access Tokens and Handling Errors doc for details.
zearth
Updated on June 05, 2022Comments
-
zearth almost 2 years
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?