Javacript code from fb in module function n8n (User Access Tokens)

Hello, I have a question about javascript code using fb libraries. I would like to make a Login Flow module as I need this token. This is one of the first tokens needed to obtain a Long-Lived Page Access Token

Hi @Max_T, are you talking about the use of npm modules inside the Function node? They would need to be installed alongside n8n and then explicitly allowed using the NODE_FUNCTION_ALLOW_EXTERNAL environment variable.

1 Like

I mean this module. this module allows code insertion.
Zrzut ekranu 2022-08-11 092243

Whatever the first one doesn’t work out, the second option is to implement it.

From looking at this page it’s not clear to me where the Function node comes into play. It seems to describe the process of building an application that includes a UI for the Facebook login.

Where exactly is the Function node supposed to do here? Code executed by the Function node would run on the server-side, so it would not be able to display UI elements or open browser windows.

1 Like

which option are we talking about?

Well, you tell me :smiley:

I have no idea what you’re trying to do with the Function node tbh. I usually fetch Facebook page access tokens whenever needed like so:

So my regular long lived access token fetches the accounts I have access to. The Facebook API response includes a list of pages along with a short lived page-specific access token for each page:

I am then using this fresh token to perform whatever operation needs performing, in this example workflow posting to a page:

Works fine, even though I haven’t used this account for ages.

1 Like

Recently, I used a token that expired after a few hours or when I closed graph api explore. that’s why I wanted to get a long-lived token but I didn’t succeed. does this scenario give the opportunity to obtain a long-lived token for the page?

No, it uses a long-lived token for my user account. Then, whenever this workflow executes it uses that long-lived token to get a short-lived page token and posts on the page using this short-lived token. Next time it runs it just fetches a new page token. This works fine, even after several months.

1 Like

How do you get a long-lived user token?

Try this approach: php - How to get non expiring access_token in Facebook? - Stack Overflow

1 Like

thank you :). I’ll get to know it soon. so at the beginning of every automation that will do something on fb I have to add this piece?

I don’t know much about Facebook, but at least that’s what works for me.

First fetching pages along with their tokens (using your main token), then perform the page action using the page-specific token. It’s a simple flow though.

On a side note, when checking the access token on Bei Facebook anmelden it says data access expires in 3 months, but the token itself never expires:

image

I have genuinely no idea what this means. It always seems to say “in about 3 months” for me, even after several months, but the token continues to work for my page-specific actions.

1 Like

Unfortunately I can’t see publish_stream or its publish_actions replacement

So this post is 10 years old, the available permissions might have changed a bit. Might simply want to try without them.

1 Like

“5. To get your permanent token, go here and use your temporary token: https://graph.facebook.com/me/accounts?access_token=REPLACE_THIS_WITH_YOUR_TEMPORARY_TOKEN

this element is in your automation if I can see correctly ?

The endpoint is used in my workflow but iirc I have swapped my access token manually once and then stored the result (the never expiring token) in my Facebook credentials for n8n.

You can verify your token via their debugging tool. Once it says Never in the Expires field you should be good to go.

1 Like

I don’t think I got what I had completely. It looks like I got an expiring token for the page. Could this also be the case?

1 Like

Yep, looks like you have a never-expiring token there. As said Facebook tokens are confusing and their docs don’t help :smiley:

1 Like

Thank you very much for help :slight_smile: . I keep doing, if I have any more problems, I will contact you.

1 Like