Extending expiry date of facebook access token in graph api beyond 2 months
Short-Term and Long-Term Tokens
User access tokens come in two forms: short-lived tokens and long-lived tokens. Short-lived tokens usually have a lifetime of about an hour or two, while long-lived tokens usually have a lifetime of about 60 days. You should not depend on these lifetimes remaining the same - the lifetime may change without warning or expire early. See more under handling errors.
So the only way left is to regenerate using code just before 60 days.
Make a GET request to graph api and filter out the access token from the JSON response
Get your user id here http://findmyfacebookid.com/
Now
Request
GET /{user-id}/accounts
Response
{
"data": [
{
"category": "Product/service",
"name": "Sample Page",
"access_token": "{access-token}",
"id": "1234567890",
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
]
},
}
https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens
You can use following api from facebook to refresh token life to 60 days and just when the token is about to expire, call the same api again with-in 60 days to refresh its life back to 60 days from that point of time Token expire is present in expires parameter and its value is in seconds
Replace CLIENT_ID and CLIENT_SECRET with their actual value
https://graph.facebook.com/oauth/access_token?client_id=&client_secret=&grant_type=fb_exchange_token&fb_exchange_token=
in ACCESS_TOKEN, put the actual token value without appending "access_token="