Renewing Facebook Graph API token automatically?

Hello,
I’m currently building an automation to post pictures on several social networks when a card on Trello is due.
Everything works fine so far, except the authorization with the Facebook Graph API, which I need for Facebook and Instagram posts.
I have to manually create the token here.

And after that, as the just created token is only valid for a few hours, I need to convert the token into a long-living one here:

The long-lived token is only valid for 2-3 months though, which makes it a bit annoying to re-new it every few months.

Is there any way I can automate the token-generating with n8n, so that it automatically creates a token when executing my workflow? Similar to how someone would authorize themselves with Facebook when creating an account somewhere.

Thanks in advance!!

Hi @tomato_planet, I am not aware of a way to automate the renewal of your personal token I am afraid.

However, in many cases this shouldn’t be required. Are you using your token to post on a FB page by any chance? If so, you can first send a request to me/accounts like so:

This returns a page-specific token for each page I have access to for me:

This page-specific token does not expire as per Facebook’s token debugger:

Using this new token you should then be able to interact with your page for an extended period of time via the API.

1 Like

Hi, thanks for your help! I am actually posting to a Facebook page and with your method I was able to get that new token for it.
The only thing that concerned me was the data access expiration listed underneath the token expiration, but apparently most permissions won’t expire, or the data access will automatically re-new itself. Facebook’s documentation about that is not too detailed. I’ll see what happens in a few months!

1 Like

I’m also interested in this but I can also see that the page access tokens expires too. if you use the debugger tool it says that it never expires but the “data access expires” says 3 months. So does this mean that every 3 months I’ll have to remind myself to re-authenticate?

Has anyone solved this in a better way?

+1 on this.

I’m also looking for a way to automate the token renewal. The page access token returned from calling /me/accounts works though and using the token debugger I was able to extend the token’s validity to about two months. Which is workable for my use-case, but would be nicer if I don’t have to worry about this anymore…