Find Expire Time for an access token

前端 未结 6 1913
星月不相逢
星月不相逢 2021-02-01 19:47

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

6条回答
  •  爱一瞬间的悲伤
    2021-02-01 20:46

    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
    

提交回复
热议问题