> ## Agent Instructions
>
> Base URL: https://api.anysite.io
> Authentication: send the `access-token` header. Do NOT use `Authorization: Bearer`.
> Full endpoint catalog: https://app.anysite.io/docs
# Reddit 节点

使用 Anysite Reddit 节点在 n8n 工作流中提取 Reddit 数据

## 概述

Anysite Reddit 节点允许您在 n8n 工作流中从 Reddit 提取有价值的数据。搜索帖子、监控子版块、分析讨论并跟踪社区情感。

## 节点配置

### 认证

  从下拉菜单中选择您的 Anysite API 凭证，或创建新凭证。

### 可用操作

#### 搜索帖子

在所有子版块或特定社区中搜索 Reddit 帖子。

**参数：**
- **Query**（必填）：用于查找帖子的搜索词
- **Subreddit**：要搜索的特定子版块（可选）
- **Sort**："relevance"、"hot"、"new"、"top"
- **Time Range**："hour"、"day"、"week"、"month"、"year"、"all"
- **Limit**：返回的最大结果数（1-100）

**输出示例：**
```json
{
  "posts": [
    {
      "id": "post123",
      "title": "How to build scalable web applications",
      "text": "Here's what I learned after building 10+ web apps...",
      "subreddit": "webdev",
      "author": "experienced_dev",
      "score": 245,
      "upvoteRatio": 0.92,
      "comments": 67,
      "created": "2024-08-26T10:30:00Z",
      "url": "https://reddit.com/r/webdev/comments/abc123/"
    }
  ]
}
```

#### 获取帖子评论

从特定 Reddit 帖子提取评论和讨论线程。

**参数：**
- **Post URL**（必填）：Reddit 帖子 URL
- **Comment Depth**：获取评论线程的深度（1-10）
- **Sort Comments**："best"、"top"、"new"、"controversial"、"old"
- **Limit**：返回的最大评论数

**输出示例：**
```json
{
  "comments": [
    {
      "id": "comment456",
      "text": "Great points! I'd also add that caching is crucial...",
      "author": "cache_expert",
      "score": 89,
      "created": "2024-08-26T11:15:00Z",
      "replies": [
        {
          "id": "reply789",
          "text": "Absolutely! Redis has been a game changer for us.",
          "author": "redis_fan",
          "score": 34
        }
      ]
    }
  ]
}
```

#### 获取子版块信息

获取特定子版块的信息和统计数据。

**参数：**
- **Subreddit Name**（必填）：子版块名称（不带 r/）
- **Include Rules**：是否包含子版块规则
- **Include Moderators**：是否包含版主列表

**输出示例：**
```json
{
  "subreddit": {
    "name": "MachineLearning",
    "title": "Machine Learning",
    "description": "This subreddit is dedicated to the discussion of machine learning...",
    "subscribers": 2500000,
    "activeUsers": 5420,
    "created": "2008-01-25T12:00:00Z",
    "isNsfw": false,
    "rules": [
      {
        "title": "Stay on topic",
        "description": "Posts must be related to machine learning"
      }
    ]
  }
}
```

#### 监控热门帖子

获取指定子版块当前的热门/trending 帖子。

**参数：**
- **Subreddits**（必填）：以逗号分隔的子版块名称列表
- **Post Limit**：每个子版块的热门帖子数量
- **Min Score**：最低赞数筛选

**输出示例：**
```json
{
  "hotPosts": [
    {
      "subreddit": "technology",
      "title": "New AI breakthrough announced by researchers",
      "score": 8750,
      "comments": 432,
      "trending": true,
      "hotnessRank": 1
    }
  ]
}
```

## 工作流示例

### 品牌监控

#### 监控提及

在相关子版块中搜索提及您的品牌、产品或竞争对手的帖子。

#### 分析情感

使用 AI 节点分析情感，识别正面/负面讨论。

#### 跟踪互动

监控围绕您品牌的赞数、评论和讨论活动。

#### 提醒团队

为高影响力提及或负面情感发送通知。

**工作流示例：**
```json
{
  "nodes": [
    {
      "name": "Monitor Brand Mentions",
      "type": "@horizondatawave/n8n-nodes-anysite.Reddit",
      "operation": "searchPosts",
      "parameters": {
        "query": "YourBrand OR YourProduct",
        "subreddit": "technology,startups,entrepreneur",
        "sort": "new",
        "limit": 50
      }
    },
    {
      "name": "Filter High Engagement",
      "type": "n8n-nodes-base.filter",
      "parameters": {
        "conditions": [
          {
            "field": "score",
            "operation": "greaterThan",
            "value": 10
          },
          {
            "field": "comments",
            "operation": "greaterThan",
            "value": 5
          }
        ]
      }
    },
    {
      "name": "Get Comments",
      "type": "@horizondatawave/n8n-nodes-anysite.Reddit",
      "operation": "getPostComments",
      "parameters": {
        "postUrl": "={{ $json.url }}",
        "commentDepth": 2,
        "limit": 25
      }
    },
    {
      "name": "Analyze Sentiment",
      "type": "n8n-nodes-base.openAi",
      "parameters": {
        "prompt": "Analyze sentiment of this Reddit discussion: {{ $json.title }} - {{ $json.text }}"
      }
    }
  ]
}
```

### 市场研究

研究客户意见和市场趋势：

1. **行业监控** - 跟踪行业特定子版块中的讨论
2. **产品反馈** - 查找提及您产品或竞争对手的帖子
3. **功能需求** - 识别常见的功能请求或痛点
4. **趋势分析** - 分析热门话题和新兴技术
5. **报告生成** - 创建每周市场研究报告

### 社区管理

监控并与您的社区互动：

1. **支持问题** - 找到寻求产品帮助的用户
2. **Bug 报告** - 识别和跟踪用户的 Bug 报告
3. **功能讨论** - 监控关于新功能的讨论
4. **社区健康** - 跟踪您子版块中的情感和互动
5. **审核提醒** - 获取需要关注的帖子通知

## 高级搜索

### 搜索运算符

使用 Reddit 的搜索语法进行精确查询：

```javascript
// 精确标题匹配
{
  "query": "title:\"How to learn machine learning\""
}

// 作者搜索
{
  "query": "author:specific_username"
}

// 多个子版块
{
  "query": "subreddit:MachineLearning OR subreddit:programming"
}

// URL 搜索
{
  "query": "url:github.com"
}

// 标签搜索
{
  "query": "flair:Discussion"
}

// 仅自发帖子
{
  "query": "self:yes machine learning tutorial"
}

// 分数筛选
{
  "query": "score:>100 artificial intelligence"
}
```

### 基于时间的分析

跟踪一段时间内的讨论：

```json
{
  "name": "Weekly Trend Analysis",
  "type": "@horizondatawave/n8n-nodes-anysite.Reddit",
  "operation": "searchPosts",
  "parameters": {
    "query": "artificial intelligence",
    "subreddit": "MachineLearning",
    "sort": "top",
    "timeRange": "week",
    "limit": 100
  }
}
```

## 数据分析

### 互动指标

计算帖子和评论的互动：

```javascript
// 互动率计算
{
  "engagementRate": "={{ ($json.comments / ($json.score || 1)) * 100 }}"
}

// 争议分数
{
  "controversyScore": "={{ (1 - $json.upvoteRatio) * 100 }}"
}

// 讨论密度
{
  "discussionDensity": "={{ $json.comments / Math.max($json.text.length / 100, 1) }}"
}
```

### 内容分析

从 Reddit 内容中提取洞察：

```json
{
  "name": "Extract Keywords",
  "type": "n8n-nodes-base.function",
  "parameters": {
    "functionCode": `
      const text = $input.first().json.text.toLowerCase();
      const keywords = text.match(/\\b\\w{4,}\\b/g) || [];
      const wordCount = {};

      keywords.forEach(word => {
        wordCount[word] = (wordCount[word] || 0) + 1;
      });

      const topKeywords = Object.entries(wordCount)
        .sort(([,a], [,b]) => b - a)
        .slice(0, 10)
        .map(([word, count]) => ({ word, count }));

      return [{ json: { ...item.json, topKeywords } }];
    `
  }
}
```

## 错误处理

### 常见错误

#### 子版块未找到

**错误：** `404 - Subreddit not found`

**解决方案：**
- 验证子版块名称拼写是否正确
- 检查子版块是否为私密或被封禁
- 在批量操作中优雅地处理缺失的子版块

#### 帖子已删除

**错误：** `404 - Post not found`

**解决方案：**
- 帖子可能已被用户或版主删除
- 首次访问时存储帖子数据
- 为缺失帖子实现回退逻辑

#### 达到速率限制

**错误：** `429 - Too many requests`

**解决方案：**
- 在请求之间添加延迟（推荐：2-3 秒）
- 实现指数退避重试逻辑
- 考虑升级 API 计划以获得更高限制

### 健壮的错误处理

```json
{
  "name": "Reddit with Error Handling",
  "type": "@horizondatawave/n8n-nodes-anysite.Reddit",
  "continueOnFail": true,
  "retryOnFail": true,
  "maxTries": 3,
  "waitBetweenTries": 3000,
  "parameters": {
    "operation": "searchPosts",
    "query": "your search query"
  }
}
```

## 集成示例

### Slack 通知

为重要讨论发送提醒：

```json
{
  "name": "High-Impact Alert",
  "type": "n8n-nodes-base.slack",
  "parameters": {
    "channel": "#marketing",
    "text": "🔥 Trending Reddit post about {{ $json.title }}\n📊 Score: {{ $json.score }} | 💬 Comments: {{ $json.comments }}\n🔗 {{ $json.url }}"
  }
}
```

### 数据库存储

存储 Reddit 数据以供分析：

```json
{
  "name": "Store in Database",
  "type": "n8n-nodes-base.postgres",
  "parameters": {
    "operation": "insert",
    "table": "reddit_posts",
    "columns": [
      "post_id",
      "title",
      "subreddit",
      "score",
      "comments",
      "created_at"
    ],
    "values": [
      "={{ $json.id }}",
      "={{ $json.title }}",
      "={{ $json.subreddit }}",
      "={{ $json.score }}",
      "={{ $json.comments }}",
      "={{ $json.created }}"
    ]
  }
}
```

### 内容聚合

将 Reddit 数据与其他来源结合：

```json
{
  "workflow": [
    "Reddit Search → Get Hot Posts",
    "Twitter Search → Find Related Tweets",
    "Google News → Get News Articles",
    "AI Analysis → Extract Common Themes",
    "Report Generation → Create Daily Brief"
  ]
}
```

## 性能技巧

### 高效的批量操作

```json
{
  "name": "Batch Subreddit Monitor",
  "type": "n8n-nodes-base.splitInBatches",
  "parameters": {
    "batchSize": 5,
    "options": {
      "reset": false
    }
  }
}
```

### 数据去重

删除重复帖子：

```javascript
// 按帖子 ID 去重
{
  "name": "Remove Duplicates",
  "type": "n8n-nodes-base.removeDuplicates",
  "parameters": {
    "compare": "selectedFields",
    "fieldsToCompare": ["id"]
  }
}
```

## 社区洞察

### 子版块分析

分析子版块健康状况和趋势：

```json
{
  "name": "Subreddit Health Check",
  "type": "@horizondatawave/n8n-nodes-anysite.Reddit",
  "operation": "getSubredditInfo",
  "parameters": {
    "subredditName": "{{ $json.subreddit }}",
    "includeRules": true,
    "includeModerators": false
  }
}
```

### 讨论质量

评估讨论质量指标：

```javascript
// 计算讨论质量分数
{
  "qualityScore": "={{ (($json.score * 0.4) + ($json.comments * 0.3) + (($json.upvoteRatio - 0.5) * 200 * 0.3)) }}"
}
```

## 后续步骤

- [LinkedIn 节点](/docs/n8n-nodes/linkedin-node?lang=zh) - LinkedIn 数据提取
- [Twitter 节点](/docs/n8n-nodes/twitter-node?lang=zh) - Twitter/X 监控
- [Instagram 节点](/docs/n8n-nodes/instagram-node?lang=zh) - Instagram 内容分析
- [工作流](/docs/n8n-nodes/workflows?lang=zh) - 预构建的工作流模板
