Reputation: 414
I have an instagram feed on my website, i created a developers.facebook.com account and made a long lived access token.
However after 60 days I have to log back in and get a new token.
You can renew an access token before it expires.
My question is... can I or should I just create a script that renews the long lived access token server side every time the page is refreshed?
Seems a bit annoying to do that to instagram servers... but what other methods would I have.. i don't know how to run a script every 59 days to get a new token..
Any ideas?
Upvotes: 3
Views: 2171
Reputation: 398
The renewal can be done only on tokens that are older than a day, so running it before that will make no difference. So, with that in mind, I run the refresh code with every call to the API. If it's already refreshed it will be ignored, so practically it will only get refreshed once a day.
Also, it's worth noting that Instagram limits the number of calls that you can make, so calling the API with every page refresh doesn't sound like a good idea. To avoid running out of quota, I cache the results and only call the API once per hour.
Here's a more detailed explanation of the exact steps that I took. It's been written with WordPress in mind, but for the most part, it doesn't matter much.
Upvotes: 5