8
n8n 中文网amn8n.com

带定时功能的X账号自动取消转推清理

高级

这是一个Social Media领域的自动化工作流,包含 28 个节点。主要使用 If, Set, Wait, Slack, Twitter 等节点。 X/Twitter转推清理与定时功能

前置要求
  • Slack Bot Token 或 Webhook URL
  • Twitter API 凭证
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "ayEitoNXtdYvLPfW",
  "meta": {
    "instanceId": "15d6057a37b8367f33882dd60593ee5f6cc0c59310ff1dc66b626d726083b48d"
  },
  "name": "带定时功能的 X 账号自动取消转推清理",
  "tags": [],
  "nodes": [
    {
      "id": "69913088-8501-421a-b049-fa8d13f36485",
      "name": "触发器 | 定时(服务器时间 09:00)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "notes": "Runs daily at 09:00 (server timezone). Adjust cadence as needed.",
      "position": [
        -192,
        560
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "439b67e8-ba4a-4711-b3ab-e5b90d64cfc8",
      "name": "配置 | 用户变量(设置字段)",
      "type": "n8n-nodes-base.set",
      "notes": "Centralizes user-editable variables for easy setup.",
      "position": [
        112,
        560
      ],
      "parameters": {
        "values": {
          "number": [
            {
              "name": "max_results",
              "value": 50
            },
            {
              "name": "batch_delay_minutes",
              "value": 1
            }
          ],
          "string": [
            {
              "name": "target_username",
              "value": "yourhandle"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 2
    },
    {
      "id": "90daaa08-e061-40a8-b127-352f41d3ccf6",
      "name": "获取 | 通过用户名获取用户 ID(X API)",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Resolves @handle → user.id via X API. Uses OAuth2 Credentials (no tokens in node).",
      "position": [
        336,
        560
      ],
      "parameters": {
        "url": "={{ `https://api.twitter.com/2/users/by/username/${$node[\"CONFIG | User Variables (Set Fields)\"].json.target_username}` }}",
        "options": {},
        "sendHeaders": true,
        "authentication": "oAuth2",
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "n8n-workflow"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "e7f8d1a4-4554-498c-bd08-608601de57dd",
      "name": "获取 | 最新推文(X API)",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Fetches recent tweets for the user. Includes fields to detect retweets.",
      "position": [
        592,
        560
      ],
      "parameters": {
        "url": "={{ `https://api.twitter.com/2/users/${$json.data.id}/tweets` }}",
        "options": {},
        "sendQuery": true,
        "authentication": "oAuth2",
        "queryParameters": {
          "parameters": [
            {
              "name": "max_results",
              "value": "={{ $node[\"CONFIG | User Variables (Set Fields)\"].json.max_results }}"
            },
            {
              "name": "tweet.fields",
              "value": "created_at,referenced_tweets"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "237c5e8a-afde-4a31-a1f3-dadabfe4b57c",
      "name": "拆分 | 每条推文一个项目",
      "type": "n8n-nodes-base.splitOut",
      "notes": "Converts the tweets array into one item per tweet.",
      "position": [
        832,
        560
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "data"
      },
      "typeVersion": 1
    },
    {
      "id": "2f57969a-11e0-47ca-aee5-b137c57a5e62",
      "name": "条件判断 | 是否为转推?",
      "type": "n8n-nodes-base.if",
      "notes": "Continue only when the first referenced_tweet is of type 'retweeted'.",
      "position": [
        1072,
        560
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cond-rt",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.referenced_tweets ? $json.referenced_tweets[0].type : '' }}",
              "rightValue": "retweeted"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e2727f92-2da8-4eda-8013-2aa9110651c8",
      "name": "循环 | 分批处理(友好处理速率限制)",
      "type": "n8n-nodes-base.splitInBatches",
      "notes": "Processes items in small batches to respect API limits.",
      "onError": "continueRegularOutput",
      "position": [
        1312,
        560
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "06dd0960-e777-4dd2-9a3a-0044208d5e46",
      "name": "发送 | 取消转推(删除转推)",
      "type": "n8n-nodes-base.twitter",
      "notes": "Deletes YOUR retweet; the original tweet remains.",
      "position": [
        1536,
        480
      ],
      "parameters": {
        "operation": "delete",
        "tweetDeleteId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "e8b4b141-caee-4df9-a132-614e82b287ea",
      "name": "等待 | API 调用间延迟",
      "type": "n8n-nodes-base.wait",
      "notes": "Spaces API calls using CONFIG.batch_delay_minutes.",
      "position": [
        1856,
        528
      ],
      "webhookId": "62cb023c-c542-4636-8b33-07dc61bded3b",
      "parameters": {
        "unit": "minutes",
        "amount": "={{ $node[\"CONFIG | User Variables (Set Fields)\"].json.batch_delay_minutes }}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "b0712253-079a-4f14-b633-64510b75ac2f",
      "name": "🟨 置顶:描述(页面副本)",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -864,
        176
      ],
      "parameters": {
        "color": "yellow",
        "width": 540,
        "height": 992,
        "content": "## 适用对象"
      },
      "typeVersion": 1
    },
    {
      "id": "8070f2cd-ded2-47d6-a7a1-261dda506d5f",
      "name": "置顶:快速设置",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        752,
        1280
      ],
      "parameters": {
        "color": "white",
        "height": 280,
        "content": "## 快速设置"
      },
      "typeVersion": 1
    },
    {
      "id": "49537208-5044-4ebb-9e50-f79ca9287acc",
      "name": "置顶:规则与自定义",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -864,
        1184
      ],
      "parameters": {
        "color": "white",
        "width": 532,
        "height": 280,
        "content": "## 规则与自定义"
      },
      "typeVersion": 1
    },
    {
      "id": "1f5027fc-0ff1-4a0c-a555-225c29314d60",
      "name": "置顶:故障排除",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        144,
        1280
      ],
      "parameters": {
        "color": "white",
        "width": 260,
        "height": 456,
        "content": "## 故障排除"
      },
      "typeVersion": 1
    },
    {
      "id": "0b1a83f8-3bb0-4eae-a0bf-2be3bde1ef62",
      "name": "置顶:触发器详情",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -256,
        160
      ],
      "parameters": {
        "color": "white",
        "height": 516,
        "content": "## 触发器 | 定时"
      },
      "typeVersion": 1
    },
    {
      "id": "521b8703-ff91-49ba-9ae8-8da8e481827a",
      "name": "置顶:配置详情",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "color": "white",
        "width": 224,
        "height": 676,
        "content": "## 配置 | 用户变量(设置字段)"
      },
      "typeVersion": 1
    },
    {
      "id": "9f368eb6-d8a8-4f2f-8c8d-b19f94a3d662",
      "name": "置顶:获取用户详情",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        48
      ],
      "parameters": {
        "color": "white",
        "width": 256,
        "height": 628,
        "content": "## 获取 | 通过用户名获取用户ID(HTTP)"
      },
      "typeVersion": 1
    },
    {
      "id": "e3927387-c8f4-4a4f-a1a4-d95ee3e7efd9",
      "name": "置顶:获取推文详情",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        512,
        48
      ],
      "parameters": {
        "color": "white",
        "width": 208,
        "height": 628,
        "content": "## 获取 | 最新推文(HTTP)"
      },
      "typeVersion": 1
    },
    {
      "id": "9db3075f-3341-4177-b4c0-42a7f97c7cd6",
      "name": "置顶:拆分详情",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        736,
        192
      ],
      "parameters": {
        "color": "white",
        "height": 484,
        "content": "## 拆分 | 每条推文一个项目"
      },
      "typeVersion": 1
    },
    {
      "id": "536b8ab0-3da5-4ffd-9029-93367c37a8ad",
      "name": "置顶:条件判断转推详情",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        192
      ],
      "parameters": {
        "color": "white",
        "height": 484,
        "content": "## 条件判断 | 是否为转推?"
      },
      "typeVersion": 1
    },
    {
      "id": "e7fe7eae-8b07-47d9-8003-eb02ee1960b6",
      "name": "置顶:循环详情",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        192
      ],
      "parameters": {
        "color": "white",
        "width": 224,
        "height": 484,
        "content": "## 循环 | 分批处理"
      },
      "typeVersion": 1
    },
    {
      "id": "aab64d61-9f7a-410a-b4c8-f654d9159848",
      "name": "置顶:取消转推详情",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1488,
        192
      ],
      "parameters": {
        "color": "white",
        "width": 320,
        "height": 484,
        "content": "## 发送 | 取消转推(删除转推)"
      },
      "typeVersion": 1
    },
    {
      "id": "70400462-8a65-4d7a-8c3a-c9a826087575",
      "name": "置顶:等待详情",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1824,
        192
      ],
      "parameters": {
        "color": "white",
        "width": 320,
        "height": 484,
        "content": "## 等待 | API调用间延迟"
      },
      "typeVersion": 1
    },
    {
      "id": "d26b1bc9-6169-48c1-bb74-a6670bc3028d",
      "name": "置顶:数据流图",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        416,
        1280
      ],
      "parameters": {
        "color": "white",
        "width": 320,
        "height": 484,
        "content": "## 数据流"
      },
      "typeVersion": 1
    },
    {
      "id": "f13bd3c3-5739-47bc-9b75-faf07f0c4ea9",
      "name": "通知 | Slack(可选)",
      "type": "n8n-nodes-base.slack",
      "notes": "Optional: Send a Slack message after each unretweet. Set credentials and channel.",
      "position": [
        2016,
        528
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "channel": "={{ '#your-channel' }}",
        "attachments": [],
        "otherOptions": {}
      },
      "typeVersion": 1
    },
    {
      "id": "54dac7b0-8123-4580-a9a7-899a53b3ca4a",
      "name": "错误时 | 捕获",
      "type": "n8n-nodes-base.errorTrigger",
      "notes": "Catches workflow errors at runtime.",
      "position": [
        16,
        1056
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "832a1fed-ce14-4dc7-bad2-9260fe1d9833",
      "name": "死信队列 | 格式化错误(设置)",
      "type": "n8n-nodes-base.set",
      "notes": "Formats an error record for a dead-letter destination (e.g., Google Sheets, Email, or Slack).",
      "position": [
        288,
        1056
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "failed_node",
              "value": "={{ $json.execution.error.node.name }}"
            },
            {
              "name": "error_message",
              "value": "={{ $json.execution.error.message }}"
            },
            {
              "name": "timestamp",
              "value": "={{ new Date().toISOString() }}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 2
    },
    {
      "id": "1ce4bb84-0bf9-4dcb-b1bc-6e4f81836d14",
      "name": "置顶:死信队列和通知",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -288,
        1280
      ],
      "parameters": {
        "color": "white",
        "width": 420,
        "height": 368,
        "content": "## 死信队列和通知(可选)"
      },
      "typeVersion": 1
    },
    {
      "id": "f86fbe64-7c65-439f-91cc-a78c57727adc",
      "name": "置顶:API端点",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1008,
        1280
      ],
      "parameters": {
        "color": "white",
        "width": 420,
        "height": 300,
        "content": "## API端点(参考)"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "4d73778e-74ab-49ab-af4b-ec2aa8149324",
  "connections": {
    "IF | Is retweet?": {
      "main": [
        [
          {
            "node": "LOOP | Split in batches (rate-limit friendly)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ON ERROR | Capture": {
      "main": [
        [
          {
            "node": "DLQ | Format error (Set)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NOTIFY | Slack (optional)": {
      "main": [
        [
          {
            "node": "LOOP | Split in batches (rate-limit friendly)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SPLIT | One item per tweet": {
      "main": [
        [
          {
            "node": "IF | Is retweet?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FETCH | Latest tweets (X API)": {
      "main": [
        [
          {
            "node": "SPLIT | One item per tweet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WAIT | Delay between API calls": {
      "main": [
        [
          {
            "node": "NOTIFY | Slack (optional)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SEND | Unretweet (delete retweet)": {
      "main": [
        [
          {
            "node": "WAIT | Delay between API calls",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CONFIG | User Variables (Set Fields)": {
      "main": [
        [
          {
            "node": "FETCH | Get user ID by username (X API)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "TRIGGER | Schedule (09:00 server time)": {
      "main": [
        [
          {
            "node": "CONFIG | User Variables (Set Fields)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FETCH | Get user ID by username (X API)": {
      "main": [
        [
          {
            "node": "FETCH | Latest tweets (X API)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LOOP | Split in batches (rate-limit friendly)": {
      "main": [
        [
          {
            "node": "SEND | Unretweet (delete retweet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 社交媒体

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流