Reputation: 892
How do I find at what time an access token is going to expire in php?
Upvotes: 2
Views: 6727
Reputation: 2054
The token you receive initially from Facebook in the signed_request expires in 2 hours or 7200000 milliseconds or 7200 seconds. If you extend the token with the below request you will receive a new expire time of 5184000 seconds in the response which converts to 60 days. What I typically do is store this time in milliseconds added to the current Unix time in milliseconds since the epoch and continually check against that time when needed.
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN
As an example I would request that sources information on the client side and do the following check..
if (response.user.sources.FACEBOOK.expires > new Date().getTime() ) {
//do something
}
Upvotes: 5
Reputation: 41
Not sure why you would want to try to determine that? An access token can expire if at anytime a user de-authorizes your app or changes their password.
read this Facebook - How-To: Handle expired access tokens
Also, I believe facebook is leading towards all apps being granted 60 day tokens. I could be wrong, but if you enable the deprecate of offline access tokens, your ap should be granted a 60 day token. that token reups to 60 days if your user revisits your ap.
Upvotes: 0