8
n8n 中文网amn8n.com

使用 GPT-4 自动生成并分发 LinkedIn 帖子到个人资料和群组

中级

这是一个AI, Marketing领域的自动化工作流,包含 14 个节点。主要使用 If, Code, Limit, HttpRequest, GoogleSheets 等节点,结合人工智能技术实现智能自动化。 使用 GPT-4 自动生成并分发 LinkedIn 帖子到个人资料和群组

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "5aaf4236c70e34e423fbdb2c7b754d19253a933bb1476d548f75848a01e473cf",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "f8952f15-2a54-4207-bf1f-ca0eea5401c2",
      "name": "限制",
      "type": "n8n-nodes-base.limit",
      "position": [
        -1880,
        120
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "fc809d41-c4c5-4161-bad6-3acda9dac3f3",
      "name": "结构化输出解析器",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -1500,
        340
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"post\": {\n\t\t\t\"type\": \"string\"\n\t\t}\t\t\n\t}\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "649c6459-7a72-4192-b172-3edea35ae770",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -1620,
        340
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "",
          "name": "OpenAi account 2"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f90a4f81-216b-470f-9885-bc9df8ca375e",
      "name": "Linkedin-Post-Topic",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "position": [
        -2320,
        120
      ],
      "parameters": {
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8/edit?usp=drivesdk",
          "cachedResultName": "Linkedin Post"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ccea615a-d960-4493-9a87-69ff1b5380c3",
      "name": "Validate-Status",
      "type": "n8n-nodes-base.if",
      "position": [
        -2100,
        120
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "ddab9b1e-0de2-4eb9-8d7b-b9f0846eb496",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.Status }}",
              "rightValue": "Pending"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "6ee612ac-5a46-4c50-b4ca-3620578e8388",
      "name": "Linedin-Post-Creator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -1660,
        120
      ],
      "parameters": {
        "text": "=You are a LinkedIn post writer. You will be given a title and your task is to create an engaging LinkedIn post based on that title.\n\nYour post should:\n\nBegin with a compelling hook related to the title\n\nInclude 3-4 paragraphs of informative content\n\nEnd with a question to encourage engagement\n\nInclude 4-6 relevant hashtags\n\nUse appropriate emojis in between\n\nImportant formatting requirements:\n\nFormat all paragraphs with proper newline characters (\\n\\n) between them\n\nEnsure the text is properly escaped for JSON\n\nDo not use double quote (\") in response or any special character\n\nDo not put asterisk\n\nKeep the overall length appropriate for LinkedIn (under 3000 characters)\n\nNow, create a LinkedIn post based on the following title:\n{{ $('Linkedin-Post-Topic').item.json['Linkedin Post Title'] }}",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "dad86e35-7fdf-4ad2-999a-39d8d7827769",
      "name": "Format-Content",
      "type": "n8n-nodes-base.code",
      "position": [
        -1280,
        120
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\n\n\n\n//const postData = $('Limit').first().json.ID;\n\n// Store this value in a workflow variable that can be accessed by other nodes\n//$variables.PostId = postData;\n\n//$workflow.setContext('postContent', postData);\n\n// Also store it in a more persistent variable if needed across workflows\n//$variables.set('postData', postData);\n\n\n\n const updatedItems = items.map((item) => {\n  item.json.output.post = JSON.stringify(item.json.output.post);\n  return item;\n});\nreturn updatedItems; \n\n\n"
      },
      "typeVersion": 2
    },
    {
      "id": "46baf319-14bd-47fe-8f5b-5eda101ead3a",
      "name": "Linkedin-User-Detail",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1060,
        120
      ],
      "parameters": {
        "url": "https://api.linkedin.com/v2/userinfo",
        "options": {
          "response": {
            "response": {}
          }
        },
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {}
          ]
        },
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2
    },
    {
      "id": "50db6b67-e0cc-4c43-accd-9f3ad8517476",
      "name": "Linkedin-post",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -840,
        120
      ],
      "parameters": {
        "url": "https://api.linkedin.com/v2/ugcPosts",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"author\": \"urn:li:person:{{ $('Linkedin-User-Detail').item.json.sub }}\",\n  \"lifecycleState\": \"PUBLISHED\",\n  \"specificContent\": {\n    \"com.linkedin.ugc.ShareContent\": {\n      \"shareCommentary\": {\n        \"text\": {{ $('Format-Content').item.json.output.post }}\n      },\n      \"shareMediaCategory\": \"NONE\"\n      }\n  },\n  \"visibility\": {\n    \"com.linkedin.ugc.MemberNetworkVisibility\": \"PUBLIC\"\n  }\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2
    },
    {
      "id": "f798cd8c-289e-493f-9d27-36a37fe72ae8",
      "name": "Get-Group-id",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -620,
        120
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1240468053,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8/edit#gid=1240468053",
          "cachedResultName": "Groups"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8/edit?usp=drivesdk",
          "cachedResultName": "Linkedin Post"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "5YFG2MAT8opHAtTt",
          "name": "Google Sheets account 2"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "049fc19a-9c29-491a-b3a7-fe9aadee6583",
      "name": "Pick 1 by 1",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -400,
        120
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "bea35dda-9e97-4b02-90a9-ce6f17ba4c5a",
      "name": "Post-Linkedin-Groups",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        -180,
        160
      ],
      "parameters": {
        "url": "https://api.linkedin.com/v2/ugcPosts",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"author\": \"urn:li:person:{{ $('Linkedin-User-Detail').item.json.sub }}\",\n  \"containerEntity\": \"urn:li:group:{{ $json.GroupIds }}\",\n  \"lifecycleState\": \"PUBLISHED\",\n  \"specificContent\": {\n    \"com.linkedin.ugc.ShareContent\": {\n      \"shareCommentary\": {\n        \"text\": {{ $('Format-Content').item.json.output.post }}\n      },\n      \"shareMediaCategory\": \"NONE\"\n    }\n  },\n  \"visibility\": {\n    \"com.linkedin.ugc.MemberNetworkVisibility\": \"PUBLIC\"\n  }\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2
    },
    {
      "id": "9887fef3-d784-446a-877d-297ad835a6ed",
      "name": "Update-Status",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -180,
        -40
      ],
      "parameters": {
        "columns": {
          "value": {
            "ID": "={{ $('Limit').item.json.ID }}",
            "Status": "Posted"
          },
          "schema": [
            {
              "id": "ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Linkedin Post Title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Linkedin Post Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Image Path",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Image Path",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "ID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8/edit?usp=drivesdk",
          "cachedResultName": "Linkedin Post"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "5YFG2MAT8opHAtTt",
          "name": "Google Sheets account 2"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "d2d2d0b1-666d-4cfc-8f3b-e528c1b7d33d",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3120,
        -360
      ],
      "parameters": {
        "width": 520,
        "height": 1480,
        "content": "LinkedIn AI Agent:自动发帖创建与分发器"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Limit": {
      "main": [
        [
          {
            "node": "Linedin-Post-Creator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick 1 by 1": {
      "main": [
        [
          {
            "node": "Update-Status",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Post-Linkedin-Groups",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get-Group-id": {
      "main": [
        [
          {
            "node": "Pick 1 by 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Linkedin-post": {
      "main": [
        [
          {
            "node": "Get-Group-id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format-Content": {
      "main": [
        [
          {
            "node": "Linkedin-User-Detail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate-Status": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Linedin-Post-Creator",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Linkedin-Post-Topic": {
      "main": [
        [
          {
            "node": "Validate-Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Linedin-Post-Creator": {
      "main": [
        [
          {
            "node": "Format-Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Linkedin-User-Detail": {
      "main": [
        [
          {
            "node": "Linkedin-post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post-Linkedin-Groups": {
      "main": [
        [
          {
            "node": "Pick 1 by 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Linedin-Post-Creator",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 人工智能, 营销

需要付费吗?

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

工作流信息
难度等级
中级
节点数量14
分类2
节点类型11
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Yaron Been

Yaron Been

@yaron-nofluff

Building AI Agents and Automations | Growth Marketer | Entrepreneur | Book Author & Podcast Host

外部链接
在 n8n.io 查看

分享此工作流