Facebook令牌更新
中级
这是一个Marketing领域的自动化工作流,包含 12 个节点。主要使用 If, Code, Webhook, HttpRequest, RespondToWebhook 等节点。 Facebook令牌获取与管理
前置要求
- •HTTP Webhook 端点(n8n 会自动生成)
- •可能需要目标 API 的认证凭证
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "MVhWWLZv7PhhLSq2",
"meta": {
"instanceId": "2c69a61055797162319204105e5a124e409f0c7fbfaba08ee106324374f4ae73",
"templateCredsSetupCompleted": true
},
"name": "Facebook 令牌更新",
"tags": [],
"nodes": [
{
"id": "ecd428ff-673c-435c-a6b3-723ae6f3f88d",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"position": [
1680,
280
],
"webhookId": "9e37ff8f-66fd-417b-97af-570e52622d7b",
"parameters": {
"path": "facebook-login",
"options": {},
"responseMode": "responseNode"
},
"typeVersion": 2
},
{
"id": "7fe9fcb7-49f3-4628-8a9f-2027f9dffd61",
"name": "如果",
"type": "n8n-nodes-base.if",
"position": [
2360,
280
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "and",
"conditions": [
{
"id": "ce391d94-03af-42d1-ae73-91bdb2e93c00",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
},
"leftValue": "={{ $('Webhook').first().json.query.code }}",
"rightValue": "login"
}
]
},
"looseTypeValidation": true
},
"typeVersion": 2.2
},
{
"id": "ded6d8fa-3add-4084-a9f2-172a5d51158b",
"name": "短期令牌",
"type": "n8n-nodes-base.httpRequest",
"onError": "continueErrorOutput",
"position": [
2720,
140
],
"parameters": {
"url": "https://graph.facebook.com/v21.0/oauth/access_token",
"options": {},
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "client_id",
"value": "={{ $('Config').first().json.app_id }}"
},
{
"name": "redirect_uri",
"value": "={{ $('Config').first().json.fb_redirect_uri }}"
},
{
"name": "client_secret",
"value": "={{ $('Config').first().json.app_secret }}"
},
{
"name": "code",
"value": "={{ $('Webhook').first().json.query.code }}"
}
]
}
},
"retryOnFail": true,
"typeVersion": 4.2,
"alwaysOutputData": false,
"waitBetweenTries": 5000
},
{
"id": "27fed69c-e476-4e19-870e-f26ed707e36a",
"name": "长期令牌",
"type": "n8n-nodes-base.httpRequest",
"position": [
3000,
-100
],
"parameters": {
"url": "https://graph.facebook.com/v21.0/oauth/access_token",
"options": {},
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "grant_type",
"value": "fb_exchange_token"
},
{
"name": "client_id",
"value": "={{ $('Config').first().json.app_id }}"
},
{
"name": "client_secret",
"value": "={{ $('Config').first().json.app_secret }}"
},
{
"name": "fb_exchange_token",
"value": "={{ $('Short-Lived Token').first().json.access_token }}"
}
]
}
},
"retryOnFail": true,
"typeVersion": 4.2,
"waitBetweenTries": 5000
},
{
"id": "94e38177-b72f-4e99-9e2f-e43bd679589b",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
1660,
-800
],
"parameters": {
"width": 920,
"height": 900,
"content": "### 获取 2 个月 Facebook 令牌的说明"
},
"typeVersion": 1
},
{
"id": "4af7f1f6-9479-4489-9282-7083cd29649c",
"name": "重定向 URL",
"type": "n8n-nodes-base.code",
"position": [
2980,
480
],
"parameters": {
"jsCode": "const config = $('Config').first().json;\n\n\nconst generateRandomState = () => {\n\treturn Math.random().toString(36).substring(2, 15) +\n\t\tMath.random().toString(36).substring(2, 15);\n}\nconst state = generateRandomState();\n\nconst correctScopes = [\n 'publish_video',\n\t\t'pages_show_list',\n\t\t'business_management',\n 'pages_read_engagement',\n 'pages_read_user_content',\n 'pages_manage_metadata',\n 'pages_manage_posts',\n 'pages_manage_engagement',\n\t];\n\nconst authUrl = `https://www.facebook.com/v22.0/dialog/oauth?client_id=${config.app_id}&redirect_uri=${config.fb_redirect_uri}&scope=${correctScopes.join(',')}&response_type=code&state=${state}`;\n\nreturn [{\n authUrl\n}];"
},
"typeVersion": 2
},
{
"id": "b415e387-17ed-4451-ae7d-b8d1fdf8ee06",
"name": "重定向",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
3740,
480
],
"parameters": {
"options": {},
"redirectURL": "={{ $json.authUrl }}",
"respondWith": "redirect"
},
"typeVersion": 1.1
},
{
"id": "d59290d9-79b5-4212-a8ad-a1a9e074bbf2",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
1840,
140
],
"parameters": {
"width": 420,
"height": 480,
"content": "编辑:"
},
"typeVersion": 1
},
{
"id": "952f17fa-efdf-4523-9d9b-ff071670e425",
"name": "便签 2",
"type": "n8n-nodes-base.stickyNote",
"position": [
2460,
460
],
"parameters": {
"width": 640,
"height": 760,
"content": ""
},
"typeVersion": 1
},
{
"id": "dbc712ba-1a95-4041-ac27-824d804726bc",
"name": "令牌",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
3700,
-100
],
"parameters": {
"options": {},
"respondWith": "text",
"responseBody": "={{ $json.access_token }}"
},
"typeVersion": 1.1
},
{
"id": "560d3c3f-a0e8-432e-904f-71cd7525fd0d",
"name": "便签 3",
"type": "n8n-nodes-base.stickyNote",
"position": [
3280,
-180
],
"parameters": {
"width": 280,
"content": "默认情况下,令牌将显示在屏幕上。但是,您可以添加一个 `node` 将令牌保存到数据库中。"
},
"typeVersion": 1
},
{
"id": "99e67d66-5179-4186-b78f-ced80ab5dd82",
"name": "配置",
"type": "n8n-nodes-base.set",
"position": [
1980,
280
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "c210cd1e-ff2d-47cb-b9c4-af1e9a91ec71",
"name": "fb_redirect_uri",
"type": "string",
"value": "https://localhost:5678/webhook/facebook-login"
},
{
"id": "3f24bd07-905f-4c3c-bd07-2661e0a95d7a",
"name": "app_id",
"type": "string",
"value": "12345678900000"
},
{
"id": "51de3a11-3e7f-4c8e-9c2c-63ae28a14eb8",
"name": "app_secret",
"type": "string",
"value": "aaabbbcccceedb6f9c91993c871"
}
]
}
},
"typeVersion": 3.4
}
],
"active": false,
"pinData": {},
"settings": {
"timezone": "Asia/Ho_Chi_Minh",
"callerPolicy": "workflowsFromSameOwner",
"executionOrder": "v1"
},
"versionId": "c2d0b26b-3366-424a-a741-20649907f008",
"connections": {
"If": {
"main": [
[
{
"node": "Short-Lived Token",
"type": "main",
"index": 0
}
],
[
{
"node": "Redirect URL",
"type": "main",
"index": 0
}
]
]
},
"Config": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "Config",
"type": "main",
"index": 0
}
]
]
},
"Redirect URL": {
"main": [
[
{
"node": "Redirect",
"type": "main",
"index": 0
}
]
]
},
"Long-Lived Token": {
"main": [
[
{
"node": "Token",
"type": "main",
"index": 0
}
]
]
},
"Short-Lived Token": {
"main": [
[
{
"node": "Long-Lived Token",
"type": "main",
"index": 0
}
],
[
{
"node": "Redirect URL",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 营销
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
使用AI将Reddit帖子转换为短视频
使用AI将Reddit帖子转换为短视频
If
Set
Code
+11
43 节点Artur
人工智能
新闻通讯管理 (n8n + Bolt.new)
职位通讯自动化系统 (N8N, Bolt.new, RapidAPI, Mails.so & ChatGPT)
If
Code
Gmail
+12
43 节点Joseph
人工智能
实时Notion Todoist双向同步模板
使用Redis的Notion Todoist实时双向同步
If
Set
Code
+26
246 节点Mario
销售
[模板] AI宠物店 v8
🐶 AI宠物店助手 - 集成GPT-4o、Google日历和WhatsApp/Instagram/Facebook
If
N8n
Set
+38
244 节点Amanda Benks
销售
YouTube视频精彩片段提取API
从YouTube视频中提取精彩片段的API
If
Set
Filter
+7
18 节点Max T
营销
使用GPT-4o、WordPress和LinkedIn发布自动化RSS内容到博客文章
使用GPT-4o、WordPress和LinkedIn发布自动化RSS内容到博客文章
If
Set
Code
+21
40 节点Immanuel
人工智能