8
n8n 中文网amn8n.com

YouTube - 获取视频统计数据

中级

这是一个Market Research领域的自动化工作流,包含 11 个节点。主要使用 If, HttpRequest, GoogleSheets, ManualTrigger, SplitInBatches 等节点。 提取YouTube视频统计数据并保存到Google Sheets

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "9I7wnSTl7wvPjxZQ",
  "meta": {
    "instanceId": "ed6d846a2fce1f660ede2e7da800724cca01dc3d0685524a3c917881b7cfcfe9"
  },
  "name": "YouTube - 获取视频统计数据",
  "tags": [
    {
      "id": "CEVEeZJa4qgPvdpK",
      "name": "youtube",
      "createdAt": "2025-05-27T02:29:43.874Z",
      "updatedAt": "2025-05-27T02:29:43.874Z"
    }
  ],
  "nodes": [
    {
      "id": "de9aba98-7d3d-4de0-bcb2-020abe4775be",
      "name": "当点击\"测试工作流\"时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -700,
        420
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "05f35e6b-52ec-4998-a3ff-99f92d70ac6d",
      "name": "If - 检查成功响应",
      "type": "n8n-nodes-base.if",
      "position": [
        180,
        120
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "bce76f94-5904-4fdb-b172-adc1134855f9",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.pageInfo.totalResults }}",
              "rightValue": 200
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "98fdd444-47af-43a0-a8d4-9df561a3eabe",
      "name": "Google Sheets - 更新数据",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        400,
        120
      ],
      "parameters": {
        "columns": {
          "value": {
            "tags": "={{ $json.items[0].snippet.tags.join(\", \") }}",
            "title": "={{ $json.items[0].snippet.title }}",
            "status": "finish",
            "duration": "={{ (d => d[1] ? `${d[1]}:${String(d[2] || 0).padStart(2, '0')}:${String(d[3] || 0).padStart(2, '0')}` : `${d[2] || 0}:${String(d[3] || 0).padStart(2, '0')}`)($json.items[0].contentDetails.duration.match(/PT(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?/)) }}\n",
            "language": "={{ $json.items[0].snippet.defaultLanguage }}",
            "channel_id": "={{ $json.items[0].snippet.channelId }}",
            "like_count": "={{ $json.items[0].statistics.likeCount }}",
            "row_number": "={{ $('Google Sheets - Get Video URLs').item.json.row_number }}",
            "thumbnails": "={{ $json.items[0].snippet.thumbnails.default.url }}",
            "view_count": "={{ $json.items[0].statistics.viewCount }}",
            "description": "={{ $json.items[0].snippet.description }}",
            "published_at": "={{ $json.items[0].snippet.publishedAt.toString().slice(0, 19).replace('T', ' ') }}",
            "channel_title": "={{ $json.items[0].snippet.channelTitle }}",
            "comment_count": "={{ $json.items[0].statistics.commentCount }}",
            "last_fetched_time": "={{ $now.toISO().toString().slice(0, 19).replace('T', ' ') }}"
          },
          "schema": [
            {
              "id": "status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "video_url",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "video_url",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "last_fetched_time",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "last_fetched_time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "description",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "thumbnails",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "thumbnails",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "tags",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "tags",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "duration",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "duration",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "view_count",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "view_count",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "like_count",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "like_count",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "comment_count",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "comment_count",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "language",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "language",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "published_at",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "published_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "channel_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "channel_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "channel_title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "channel_title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "row_number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 426418282,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1I9gyb27WiRHz--g-xi-QH1W3WppZJdSfY6L32-DyUw0/edit#gid=426418282",
          "cachedResultName": "Video Urls"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1I9gyb27WiRHz--g-xi-QH1W3WppZJdSfY6L32-DyUw0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1I9gyb27WiRHz--g-xi-QH1W3WppZJdSfY6L32-DyUw0/edit?usp=drivesdk",
          "cachedResultName": "Youtube - Get Video Statics"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "pe6UD1A6MWIk2X91",
          "name": "Google Sheets - toan.ngo"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.5
    },
    {
      "id": "f0c76306-d47b-4442-935d-61a7c01bf0bc",
      "name": "Google Sheets - 更新数据 - 错误",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        400,
        320
      ],
      "parameters": {
        "columns": {
          "value": {
            "status": "error",
            "row_number": "={{ $('Google Sheets - Get Video URLs').item.json.row_number }}",
            "last_fetched_time": "={{ $now.toISO().toString().slice(0, 19).replace('T', ' ') }}"
          },
          "schema": [
            {
              "id": "status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "video_url",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "video_url",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "last_fetched_time",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "last_fetched_time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "title",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "description",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "thumbnails",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "thumbnails",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "tags",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "tags",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "duration",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "duration",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "view_count",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "view_count",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "like_count",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "like_count",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "comment_count",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "comment_count",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "language",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "language",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "published_at",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "published_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "channel_id",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "channel_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "channel_title",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "channel_title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "row_number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 426418282,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1I9gyb27WiRHz--g-xi-QH1W3WppZJdSfY6L32-DyUw0/edit#gid=426418282",
          "cachedResultName": "Video Urls"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1I9gyb27WiRHz--g-xi-QH1W3WppZJdSfY6L32-DyUw0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1I9gyb27WiRHz--g-xi-QH1W3WppZJdSfY6L32-DyUw0/edit?usp=drivesdk",
          "cachedResultName": "Youtube - Get Video Statics"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "pe6UD1A6MWIk2X91",
          "name": "Google Sheets - toan.ngo"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.5
    },
    {
      "id": "0c71b117-aeae-45d3-806d-9e89ef1ffb39",
      "name": "HTTP - 查找视频数据",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        -40,
        145
      ],
      "parameters": {
        "url": "https://www.googleapis.com/youtube/v3/videos?",
        "options": {},
        "sendQuery": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "id",
              "value": "={{ $json.video_url.match(/(?:youtube(?:-nocookie)?\\.com\\/(?:[^\\/\\n\\s]+\\/\\S+\\/|(?:v|e(?:mbed)?)\\/|\\S*?[?&]v=)|youtu\\.be\\/)([a-zA-Z0-9_-]{11})/)[1] }}"
            },
            {
              "name": "part",
              "value": "contentDetails,snippet,statistics"
            }
          ]
        },
        "nodeCredentialType": "youTubeOAuth2Api"
      },
      "credentials": {
        "youTubeOAuth2Api": {
          "id": "KhD0GLQGWl8MtqCs",
          "name": "YouTube - toan.ngo"
        }
      },
      "typeVersion": 4.2,
      "alwaysOutputData": false
    },
    {
      "id": "e8e9b10e-0456-4c5b-855c-79602c0f9f9d",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1580,
        -160
      ],
      "parameters": {
        "width": 720,
        "height": 1480,
        "content": "## [Agent Circle的N8N工作流] YouTube视频统计数据爬虫 - 立即试用!"
      },
      "typeVersion": 1
    },
    {
      "id": "b9e277aa-b307-4a75-997c-6ef319b13e28",
      "name": "Google Sheets - 获取视频网址",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -480,
        420
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "ready",
              "lookupColumn": "status"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 426418282,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1I9gyb27WiRHz--g-xi-QH1W3WppZJdSfY6L32-DyUw0/edit#gid=426418282",
          "cachedResultName": "Video Urls"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1I9gyb27WiRHz--g-xi-QH1W3WppZJdSfY6L32-DyUw0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1I9gyb27WiRHz--g-xi-QH1W3WppZJdSfY6L32-DyUw0/edit?usp=drivesdk",
          "cachedResultName": "Youtube - Get Video Statics"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "pe6UD1A6MWIk2X91",
          "name": "Google Sheets - toan.ngo"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "331af5c0-428a-41a6-a9ca-268cf9b50da3",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -760,
        -140
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 800,
        "content": "## 1. 从Google Sheets读取视频URL"
      },
      "typeVersion": 1
    },
    {
      "id": "9e1e2bb8-cf50-404f-a637-0f144b60af7f",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -100,
        -140
      ],
      "parameters": {
        "color": 7,
        "height": 800,
        "content": "## 2. 从YouTube API获取视频统计数据"
      },
      "typeVersion": 1
    },
    {
      "id": "295fa90d-029e-4b7d-a8e0-e40f8f791c0f",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -140
      ],
      "parameters": {
        "color": 7,
        "width": 500,
        "height": 800,
        "content": "## 3. 将结果写回Google Sheets"
      },
      "typeVersion": 1
    },
    {
      "id": "e33bf702-f7c8-4174-aedb-6ac0db968a26",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -260,
        420
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "8f09f1fc-d50e-40c8-b0d8-9867f8b7f7c8",
  "connections": {
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "HTTP - Find Video Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP - Find Video Data": {
      "main": [
        [
          {
            "node": "If - Check Success Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets - Update Data": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If - Check Success Response": {
      "main": [
        [
          {
            "node": "Google Sheets - Update Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Google Sheets - Update Data - Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets - Get Video URLs": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Google Sheets - Get Video URLs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets - Update Data - Error": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 市场调研

需要付费吗?

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

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

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

作者
Agent Circle

Agent Circle

@agentcircle

Agent Circle - A growing marketplace of AI agents, workflows, and toolkits — built to help teams automate smarter and scale faster

外部链接
在 n8n.io 查看

分享此工作流