12

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?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
zearth
  • 151
  • 1
  • 1
  • 8
  • when you get the token it tells you when it expires too. So you can get it from the start, save it and compute if its still available at any given moment. – Andrew Feb 10 '12 at 21:39
  • hi then for the reply, how can I extract it using facebook PHP SDK? sorry if I can't get your point but I'm not sure where to look at, is there a possible link in the developers documentation so I can study that part? or possible link that explaning about this part? – zearth Feb 10 '12 at 21:53

2 Answers2

3

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

Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
  • @phirschybar, There was a mistake in the sample code. Try it now, if you still have no `expires`, than probably you have no a `signed_request` at all, try to `print_r($signedRequest)` in that case to figure it out. – Juicy Scripter Mar 31 '12 at 18:56
  • I have the same issue, `expire` field is missing. – Roni Jul 11 '12 at 09:13
  • 3
    https://developers.facebook.com/bugs/467866233242810/ Bug Exists for 6 months... oh joy ! – Roni Jul 11 '12 at 09:22
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.

Dhiren Patel
  • 645
  • 4
  • 6
  • Although, all apps should support tokens being invalidated at any time (the user unauthorized you etc) and should not rely on using a backchannel for this information. – Sean Kinsey Oct 25 '12 at 07:36
  • 3
    The precise link is the following : https://developers.facebook.com/docs/facebook-login/access-tokens#debug and the API endpoint is ```GET /debug_token?input_token={input-token}&access_token={access-token}``` – Louis Ameline Apr 22 '14 at 15:38