Instagram Feed as Gallery

HI.
Trying to setup a client’s Instagram account on their website as a gallery feed.
Searches return paid apps which do not make sense.
I am just looking for a simple way to show feed from the account via API.
I got a bit confused with the Token and Facebook and token refresh and stuff.

Has anyone done this with Wappler or via JS?
Any simple articles will be helpful as well.

Setup an oauth2 provider for instagram and access their basic display api. The biggest problem is indeed the tokens, when you login you get an authorization code, this is then exchanged for an access token and optionally an refresh token. You then use the access token to access the api. The problem is that the standard acces token that you get expires after 1 hour, you have to exchange it for a long-lived access token (60 days), you can do this with the refresh token. You also have to refresh the long-lived access token again before it expires.

We have most of the logic build-in with the oauth2 provider, it will do the exchange of the exchange of the authorization code for an access token for you. It will store the access token and refresh token in a session. You can then use the oauth2 provider in your api calls. When the access token is almost expires or it is expired then the oauth2 provider will try to exchange the access token for a new one.

Problem with the facebook api is that it will not allow you to exchange the token when it is expired and it also doesn’t like it when you request a new token to fast. So you will need some scheduler that will handle the refresh.

Thanks for that Patrick.

The feed is of the website’s company, not an end-user, so how will the login part work?
I can’t keep it stored in session.

I can generate the refresh token one-time with a dummy project and hard-code it, but as you have mentioned, it will expire.

Generate the access token and refresh token and store them in a database. Set Token Handling to Self Maintain and use the access token and refresh token from the database in the oauth provider.

If you use NodeJS then you can use the Schedule to run an action each day or even some longer period. In that action you do a refresh of the access token. The oauth module has an action for the refresh, but it seems to be missing in the Wappler UI when I checked (perhaps @George can add it). Execute the refresh action, it should return a new access token with which you then replace your previous access token in the database.

That sounds great. Will try it out soon and get back to you. Thanks. :slight_smile:

Hi @sid, did you succeed in doing this? :thinking: :slight_smile:

Yes. We implemented our own refresh token API call, running inside a scheduler as suggested by Patrick.
Our use case is to show just our personal feed… so after initial token is generated from Facebook Dev portal apps section, we stored that in the DB, and now use it to keep refreshing the access token and get latest feed.