Expiry Time of facebook access token

梦想的初衷 提交于 2019-12-06 13:43:15

问题


How do I find at what time an access token is going to expire in php?


回答1:


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.

Extending the token:

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
}



回答2:


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.



来源:https://stackoverflow.com/questions/11337840/expiry-time-of-facebook-access-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!