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!