Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Expire Time for an access token

Tags:

Is there any way to use the graph api to find out when a page access token, or application token will expire?

like image 800
Nix Avatar asked Apr 13 '12 22:04

Nix


Video Answer


2 Answers

Update: There is a new API endpoint to access information about an access token. You can find info here: Debugging Access Tokens and Handling Errors

https://graph.facebook.com/debug_token?input_token=INPUT_TOKEN&access_token=ACCESS_TOKEN

  • input_token: the Access Token to debug
  • access_token: your App Access Token or a valid User Access Token from a developer of the app.

--

You should try to make sure that you store each token's expiration time along with the access token when you get it. For a page access token, that means storing the expiration time of the user access token. If you would like to manually discover expiration times for tokens you have today, you should use Facebook's Access Token Debugger tool. However, you should not be relying on expiration times alone -- in practice, many tokens will expire much earlier than their expiration time.

Application access tokens will never expire, unless the application secret key is reset.

Page access tokens last up to 60 days (5184000 seconds), but more importantly, they last as long as the user access token that was used to acquire them. So they will be invalidated as soon as the user that you got them from:

  • logs out of FB.
  • changes password.
  • deauthorizes your application.

Basically, when you lose the user's token, you will lose the page's token. Instead, you should retrieve page access tokens once per user access token. If you throw out a user access token, throw out the page token. You should not be trying to store page access tokens for any significant period of time. Instead you should get them as needed and forget them when a user's session dies.

To get a new page access token:

https://graph.facebook.com/PAGEID?fields=access_token&access_token=USER_ACCESS_TOKEN 
like image 55
AndrewF Avatar answered Sep 21 '22 07:09

AndrewF


Access Token Debugger

https://developers.facebook.com/tools/debug/access_token

Does not use the Graph API... but a very useful tool for manual debugging.

like image 21
Chris Jacob Avatar answered Sep 22 '22 07:09

Chris Jacob