Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract Facebook Access token Expiration Info

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?

like image 308
zearth Avatar asked Feb 10 '12 21:02

zearth


People also ask

How do I get expiry time from access token?

Go to Dashboard > Applications > APIs and click the name of the API to view. Locate the Token Expiration (Seconds) field, and enter the appropriate access token lifetime (in seconds) for the API. Default value is 86,400 seconds (24 hours). Maximum value is 2,592,000 seconds (30 days).

Do Facebook app access tokens expire?

When your app uses Facebook Login to authenticate someone, it receives a User access token. If your app uses one of the Facebook SDKs, this token lasts for about 60 days. However, the SDKs automatically refresh the token whenever the person uses your app, so the tokens expire 60 days after last use.

How do I get a long lived access token on Facebook?

To get a long-lived User access token, send a GET request to the /oauth/access_token endpoint. Replace APP-ID , APP-SECRET , and SHORT-LIVED-USER-ACCESS-TOKEN with your information. This token is valid for 60 days.


1 Answers

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);

like image 127
Juicy Scripter Avatar answered Oct 30 '22 13:10

Juicy Scripter