Search code examples
phpfacebookinstagram-graph-api

Automatically extend facebook user access token beyond 60 days for Instagram feed


Per FB documentation for long-lived token retrieved by Facebook SDK -

Native mobile apps using Facebook's SDKs get long-lived User access tokens, good for about 60 days. These tokens are refreshed once per day, when the person using your app makes a request to Facebook's servers. If no requests are made, the token will expire after about 60 days and the person will have to go through the login flow again to get a new token.

It seems there's a way to extend the token beyond 60 days by periodically making a request to FB servers. My web app is using the Facebook PHP SDK to retrieve a user's Instagram feed. I tried running a daily background cron to make a request for all authorized users (i.e those that have allowed my app to access their accounts) to attempt the above. However the result is inconclusive at best. I seem to be able to have access for longer than 60 days for some accounts, and for others I just got the error "Error validating access token: Session has expired on...".

I've tried to read all documentations, plus almost all of the related questions here on SO and still can't find a conclusive, up to date source of information.

Has anyone managed to extend the long-lived token reliably? Surely forcing your user to go through the whole login flow is quite inconvenient?


Solution

  • Facebook has released Instagram Basic Display API that allows for long-lived access token to be refreshed before it expires.

    This is perfect for app that only requires "read-access" to user's profile, images, videos, and albums like ours. Hope this helps people in similar situation.