8
n8n 中文网amn8n.com

使用Meta Graph API和系统用户令牌自动化Instagram和Facebook发帖

高级

这是一个Social Media领域的自动化工作流,包含 22 个节点。主要使用 Code, Wait, HttpRequest, ManualTrigger, ScheduleTrigger 等节点。 使用Meta Graph API和系统用户令牌自动化Instagram和Facebook发帖

前置要求
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "805a1da4490c39f62729f8489b312a775cb04286f77152b4febdc1f1642e5967",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "4fccdc64-1eb2-43a6-82c5-5ebcea2b801b",
      "name": "当点击“执行工作流”时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -560,
        480
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "738fabc1-5282-442b-a275-a3943bff890e",
      "name": "发布到 Instagram",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -300,
        480
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v19.0/<YOUR PAGE ID HERE>/media",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "image_url",
              "value": "<YOUR IMAGE URL HERE>"
            },
            {
              "name": "caption",
              "value": "<YOUR CAPTION HERE>"
            }
          ]
        },
        "nodeCredentialType": "facebookGraphApi"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "szDaIQHhZqLlJHII",
          "name": "Facebook Graph account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "da899479-cfaa-4771-bc31-bdb0d4e4a3b7",
      "name": "发布 Instagram 帖子",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        100,
        480
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v19.0/17841404935066235/media_publish",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "creation_id",
              "value": "={{ $json.id }}"
            }
          ]
        },
        "nodeCredentialType": "facebookGraphApi"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "szDaIQHhZqLlJHII",
          "name": "Facebook Graph account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "b6cd01bd-f98f-4092-81f2-1b8f6e6c4b27",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1320,
        -300
      ],
      "parameters": {
        "width": 540,
        "height": 1900,
        "content": "**如何生成用于 Instagram + Facebook 页面发布的 Facebook 短期访问令牌**"
      },
      "typeVersion": 1
    },
    {
      "id": "fe0a05a4-5e13-4109-86c1-1da8fc5e7a9a",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -720,
        -300
      ],
      "parameters": {
        "width": 1460,
        "height": 540,
        "content": "Facebook 仅在您已验证的情况下才会给您\"长期令牌\"。如果您正在测试或未验证,可以使用以下方法。"
      },
      "typeVersion": 1
    },
    {
      "id": "cce6d146-599e-439a-bff6-fc0870a8df02",
      "name": "刷新令牌",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -300,
        -120
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v19.0/oauth/access_token",
        "options": {},
        "sendQuery": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "grant_type",
              "value": "fb_exchange_token"
            },
            {
              "name": "client_id",
              "value": "<Your Client ID>"
            },
            {
              "name": "client_secret",
              "value": "<Your Secret Here>"
            },
            {
              "name": "fb_exchange_token",
              "value": "<your short token>"
            }
          ]
        },
        "nodeCredentialType": "facebookGraphApi"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "szDaIQHhZqLlJHII",
          "name": "Facebook Graph account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "e93d120b-ef7b-491c-bfcf-3d6a1ec62786",
      "name": "定时触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -680,
        -120
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "daysInterval": 30,
              "triggerAtHour": 1
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "097bde34-8787-4e0d-9dec-90f2de9c0aa1",
      "name": "获取当前令牌",
      "type": "n8n-nodes-base.code",
      "position": [
        -500,
        -120
      ],
      "parameters": {
        "jsCode": "const staticData = $getWorkflowStaticData('global');\nreturn [{\n  json: {\n    token: staticData.fb_token\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "75f115f5-eee8-4e85-bd35-8c70ac4c13c5",
      "name": "推送到静态数据",
      "type": "n8n-nodes-base.code",
      "position": [
        -80,
        -120
      ],
      "parameters": {
        "jsCode": "const staticData = $getWorkflowStaticData('global');\nstaticData.fb_token = $json.access_token;\n\nreturn [{\n  json: {\n    status: 'Token saved to static data',\n    token: staticData.fb_token\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "95439d8f-c568-497a-901f-69b2cfd7172f",
      "name": "从静态数据获取令牌",
      "type": "n8n-nodes-base.code",
      "position": [
        -640,
        60
      ],
      "parameters": {
        "jsCode": "const staticData = $getWorkflowStaticData('global');\nreturn [{\n  json: {\n    token: staticData.fb_token\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "b13db71d-0620-46d4-a9f9-17b693930af4",
      "name": "发布到 Instagram1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -420,
        60
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v19.0/<Instagram Page ID>/media",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "image_url",
              "value": "<Your Image Url>"
            },
            {
              "name": "caption",
              "value": "<Your Caption>"
            },
            {
              "name": "access_token",
              "value": "={{ $json.token }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "72bb812b-7ccf-4703-8d6d-35feb3576792",
      "name": "发布 Instagram 帖子1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -60,
        60
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v19.0/<your instagram page id>/media_publish",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "creation_id",
              "value": "={{ $json.id }}"
            },
            {
              "name": "access_token",
              "value": "={{ $('Get Token from static Data').item.json.token }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "5a279b05-d40f-47b6-a7f1-56daa21ff773",
      "name": "发布到 Facebook",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        780,
        480
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v19.0/266271423823110/photos",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "url",
              "value": "https://images.pexels.com/photos/5475816/pexels-photo-5475816.jpeg?auto=compress&cs=tinysrgb&fit=crop&h=627&w=1200"
            },
            {
              "name": "caption",
              "value": "This is the caption for the post"
            },
            {
              "name": "access_token",
              "value": "={{ $json.data[0].access_token }}"
            }
          ]
        },
        "nodeCredentialType": "facebookGraphApi"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "szDaIQHhZqLlJHII",
          "name": "Facebook Graph account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "395e1149-cb03-45f3-97b1-1a5fe8e4ac06",
      "name": "使用系统令牌获取页面令牌",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        320,
        480
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v19.0/me/accounts",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "facebookGraphApi"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "szDaIQHhZqLlJHII",
          "name": "Facebook Graph account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "926c9774-6e9b-427f-8916-3ccf4ce30012",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -720,
        340
      ],
      "parameters": {
        "color": 5,
        "width": 1760,
        "height": 360,
        "content": "使用永不过期的永久令牌"
      },
      "typeVersion": 1
    },
    {
      "id": "1ef57c3d-fc04-4107-82e3-3faf0dcfe2ce",
      "name": "便签说明4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1080,
        -80
      ],
      "parameters": {
        "width": 680,
        "height": 1220,
        "content": "如何创建永久系统用户令牌(推荐)"
      },
      "typeVersion": 1
    },
    {
      "id": "4eaa4823-7601-49d1-9cec-da232ac7ee62",
      "name": "获取正确的页面令牌",
      "type": "n8n-nodes-base.code",
      "position": [
        560,
        480
      ],
      "parameters": {
        "jsCode": "const page = $json.data.find(p => p.id === '266271423823110');\nreturn [{ json: { access_token: page.access_token } }];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "abb870c7-9241-4503-9fb1-348dcbf29dad",
      "name": "等待2秒",
      "type": "n8n-nodes-base.wait",
      "position": [
        -120,
        480
      ],
      "webhookId": "c40b180e-016c-4648-898a-5942b8a9b00d",
      "parameters": {
        "amount": 2
      },
      "typeVersion": 1.1
    },
    {
      "id": "70120c0d-d21a-4fa2-b8d5-81931c198c65",
      "name": "等待2秒1",
      "type": "n8n-nodes-base.wait",
      "position": [
        -240,
        60
      ],
      "webhookId": "c40b180e-016c-4648-898a-5942b8a9b00d",
      "parameters": {
        "amount": 2
      },
      "typeVersion": 1.1
    },
    {
      "id": "4cde11f4-c12f-4827-94ce-9ee9d11d821d",
      "name": "使用系统令牌获取页面令牌1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        160,
        60
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v19.0/me/accounts",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "access_token",
              "value": "={{ $('Get Token from static Data').item.json.token }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "f7581a1c-d095-4fe9-951c-cc6b6108156a",
      "name": "获取正确的页面令牌1",
      "type": "n8n-nodes-base.code",
      "position": [
        380,
        60
      ],
      "parameters": {
        "jsCode": "const page = $json.data.find(p => p.id === '<YOUR PAGE ID HERE>');\nreturn [{ json: { access_token: page.access_token } }];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "306bb9bb-5ba0-4ecd-96a8-33e3ec292526",
      "name": "发布到 Facebook1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        580,
        60
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v19.0/<YOUR PAGE ID HERE>/photos",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "url",
              "value": "<YOUR IMAGE URL HERE>"
            },
            {
              "name": "caption",
              "value": "<YOUR CAPTION  HERE>"
            },
            {
              "name": "access_token",
              "value": "={{ $json.data[0].access_token }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    }
  ],
  "pinData": {},
  "connections": {
    "Refresh token": {
      "main": [
        [
          {
            "node": "Push to Static Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 2 Second": {
      "main": [
        [
          {
            "node": "Publish instagram post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 2 Second1": {
      "main": [
        [
          {
            "node": "Publish instagram post1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Current Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Current Token": {
      "main": [
        [
          {
            "node": "Refresh token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post to Instagram": {
      "main": [
        [
          {
            "node": "Wait 2 Second",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post to Instagram1": {
      "main": [
        [
          {
            "node": "Wait 2 Second1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Correct Page Token": {
      "main": [
        [
          {
            "node": "Post to Facebook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Publish instagram post": {
      "main": [
        [
          {
            "node": "Use System token to get page token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Correct Page Token1": {
      "main": [
        [
          {
            "node": "Post to Facebook1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Publish instagram post1": {
      "main": [
        [
          {
            "node": "Use System token to get page token1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Token from static Data": {
      "main": [
        [
          {
            "node": "Post to Instagram1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Use System token to get page token": {
      "main": [
        [
          {
            "node": "Get Correct Page Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Use System token to get page token1": {
      "main": [
        [
          {
            "node": "Get Correct Page Token1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Post to Instagram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 社交媒体

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量22
分类1
节点类型6
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者

specializing in automation, AI integrations, and workflow optimization. I build high-impact n8n workflows that connect Salesforce, Outlook, RingCentral, and more. Reach out if you need help making your systems talk to each other.

外部链接
在 n8n.io 查看

分享此工作流