> ## 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
# Twitter 节点

使用 Anysite Twitter 节点在 n8n 工作流中提取 Twitter/X 数据

## 概述

Anysite Twitter 节点使您能够在 n8n 工作流中提取 Twitter (X) 数据。搜索推文、分析用户资料、监控标签并跟踪社交媒体对话。

## 节点配置

### 认证

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

### 可用操作

#### 搜索用户

按用户名、简介或其他条件搜索 Twitter 用户。

**参数：**
- **Query**（必填）：用于查找用户的搜索词
- **Result Type**："recent"、"popular" 或 "mixed"
- **Limit**：返回的最大结果数（1-100）

**输出示例：**
```json
{
  "users": [
    {
      "id": "twitter123",
      "username": "johnsmith_dev",
      "displayName": "John Smith",
      "bio": "Senior Software Engineer | Python enthusiast",
      "followers": 15000,
      "following": 800,
      "verified": false,
      "location": "San Francisco, CA",
      "profileImageUrl": "https://pbs.twimg.com/profile_images/..."
    }
  ]
}
```

#### 获取用户帖子

从特定 Twitter 用户提取推文和帖子。

**参数：**
- **Username**（必填）：Twitter 用户名（不带 @）
- **Tweet Count**：要检索的推文数量（1-100）
- **Include Replies**：是否包含回复推文
- **Include Retweets**：是否包含转推

**输出示例：**
```json
{
  "tweets": [
    {
      "id": "tweet456",
      "text": "Just shipped a new feature! Excited to see how users respond 🚀",
      "createdAt": "2024-08-26T14:30:00Z",
      "engagement": {
        "likes": 125,
        "retweets": 32,
        "replies": 18,
        "views": 2500
      },
      "mediaUrls": [],
      "hashtags": ["#ProductLaunch", "#TechStartup"]
    }
  ]
}
```

#### 搜索推文

按关键词、标签或短语搜索推文。

**参数：**
- **Query**（必填）：搜索查询（支持运算符）
- **Result Type**："recent"、"popular" 或 "mixed"
- **Language**：语言筛选（可选）
- **Date Range**：搜索的时间范围

**输出示例：**
```json
{
  "tweets": [
    {
      "id": "search789",
      "text": "The future of AI development is looking incredible! #AI #MachineLearning",
      "author": {
        "username": "ai_researcher",
        "displayName": "Dr. Sarah Wilson"
      },
      "createdAt": "2024-08-26T12:00:00Z",
      "engagement": {
        "likes": 89,
        "retweets": 24,
        "replies": 12
      }
    }
  ]
}
```

#### 获取推文详情

获取特定推文的详细信息。

**参数：**
- **Tweet ID**（必填）：Twitter 推文标识符
- **Include Thread**：是否包含推文线程上下文

**输出示例：**
```json
{
  "tweet": {
    "id": "tweet123",
    "text": "Thread about building scalable APIs: 1/8",
    "author": {
      "username": "backend_expert",
      "followers": 25000
    },
    "engagement": {
      "likes": 245,
      "retweets": 89,
      "replies": 34
    },
    "threadTweets": [
      {
        "id": "tweet124",
        "text": "First, consider your data architecture..."
      }
    ]
  }
}
```

## 工作流示例

### 社交媒体监控

#### 监控品牌提及

搜索提及您的品牌、产品或竞争对手的推文。

#### 分析情感

使用 AI 节点分析情感，并将提及分类为正面、负面或中性。

#### 识别影响者

找到提及您品牌的高互动用户并评估他们的影响力。

#### 提醒团队

为重要提及或负面情感向您的社交媒体团队发送通知。

**工作流示例：**
```json
{
  "nodes": [
    {
      "name": "Monitor Brand",
      "type": "@horizondatawave/n8n-nodes-anysite.Twitter",
      "operation": "searchTweets",
      "parameters": {
        "query": "YourBrand OR @YourHandle OR #YourHashtag",
        "resultType": "recent",
        "limit": 100
      }
    },
    {
      "name": "Sentiment Analysis",
      "type": "n8n-nodes-base.openAi",
      "parameters": {
        "operation": "analyze",
        "prompt": "Analyze sentiment: {{ $json.text }}"
      }
    },
    {
      "name": "Filter Negative",
      "type": "n8n-nodes-base.filter",
      "parameters": {
        "conditions": [
          {
            "field": "sentiment",
            "operation": "equal",
            "value": "negative"
          }
        ]
      }
    },
    {
      "name": "Alert Team",
      "type": "n8n-nodes-base.slack",
      "parameters": {
        "channel": "#social-media",
        "text": "🚨 Negative mention detected: {{ $json.text }}"
      }
    }
  ]
}
```

### 影响者外联

查找和分析潜在的影响者合作伙伴：

1. **搜索影响者** - 在您的细分市场中找到高互动用户
2. **分析资料** - 检查粉丝数、互动率和内容主题
3. **内容分析** - 审查最近的帖子以确保品牌一致性和真实互动
4. **联系信息** - 提取简介链接和联系方式
5. **CRM 集成** - 将合格的影响者添加到您的外联数据库

### 趋势分析

跟踪热门话题和标签：

1. **标签监控** - 跟踪与您行业相关的特定标签
2. **互动追踪** - 监控推文表现和病毒式内容
3. **竞争对手分析** - 查看竞争对手发布的内容
4. **内容机会** - 为您的内容日历识别热门话题
5. **报告** - 生成每周趋势报告

## 高级搜索查询

### 搜索运算符

使用 Twitter 的高级搜索运算符：

```javascript
// 精确短语搜索
{
  "query": "\"artificial intelligence\""
}

// 排除转推
{
  "query": "machine learning -RT"
}

// 来自特定用户
{
  "query": "from:elonmusk"
}

// 提及用户
{
  "query": "@openai"
}

// 多个标签
{
  "query": "#AI #MachineLearning"
}

// 基于位置
{
  "query": "startup near:\"San Francisco\""
}

// 日期范围
{
  "query": "product launch since:2024-08-01 until:2024-08-31"
}
```

### 互动筛选

按互动指标筛选：

```json
{
  "name": "High Engagement Filter",
  "type": "n8n-nodes-base.filter",
  "parameters": {
    "conditions": [
      {
        "field": "engagement.likes",
        "operation": "greaterThan",
        "value": 100
      },
      {
        "field": "engagement.retweets",
        "operation": "greaterThan",
        "value": 20
      }
    ]
  }
}
```

## 错误处理

### 常见错误

#### 超出速率限制

**错误：** `429 - Too Many Requests`

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

#### 推文未找到

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

**解决方案：**
- 推文可能已被删除或设为私密
- 验证推文 ID 是否正确
- 在工作流中优雅地处理缺失的推文

#### 用户被封禁

**错误：** `403 - User account suspended`

**解决方案：**
- 在批量操作中跳过被封禁的账户
- 更新您的用户数据库以标记被封禁的账户
- 实现错误处理以继续工作流

### 重试配置

```json
{
  "name": "Twitter with Retry",
  "type": "@horizondatawave/n8n-nodes-anysite.Twitter",
  "retryOnFail": true,
  "maxTries": 3,
  "waitBetweenTries": 5000,
  "parameters": {
    "operation": "searchTweets",
    "query": "your search query"
  }
}
```

## 数据处理

### 推文分析

从推文数据中提取洞察：

```javascript
// 计算互动率
{
  "engagementRate": "={{ ($json.engagement.likes + $json.engagement.retweets + $json.engagement.replies) / $json.engagement.views * 100 }}"
}

// 提取标签
{
  "hashtags": "={{ $json.text.match(/#\w+/g) }}"
}

// 检查是否为认证用户
{
  "isInfluencer": "={{ $json.author.verified || $json.author.followers > 10000 }}"
}
```

### 内容分类

使用 AI 对推文进行分类：

```json
{
  "name": "Classify Content",
  "type": "n8n-nodes-base.openAi",
  "parameters": {
    "operation": "classify",
    "prompt": "Classify this tweet into categories (Product, Marketing, Support, Other): {{ $json.text }}"
  }
}
```

## 集成示例

### Google Sheets 导出

将推文数据导出到电子表格：

```json
{
  "name": "Export to Sheets",
  "type": "n8n-nodes-base.googleSheets",
  "parameters": {
    "operation": "append",
    "sheetId": "your-sheet-id",
    "values": [
      "={{ $json.author.username }}",
      "={{ $json.text }}",
      "={{ $json.createdAt }}",
      "={{ $json.engagement.likes }}",
      "={{ $json.engagement.retweets }}"
    ]
  }
}
```

### Webhook 通知

发送实时警报：

```json
{
  "name": "Webhook Alert",
  "type": "n8n-nodes-base.webhook",
  "parameters": {
    "httpMethod": "POST",
    "responseMode": "onReceived",
    "options": {
      "data": {
        "tweet": "={{ $json.text }}",
        "author": "={{ $json.author.username }}",
        "engagement": "={{ $json.engagement.likes }}"
      }
    }
  }
}
```

## 性能优化

### 批量处理

高效处理大型数据集：

```json
{
  "name": "Process in Batches",
  "type": "n8n-nodes-base.splitInBatches",
  "parameters": {
    "batchSize": 25
  }
}
```

### 缓存

缓存频繁访问的数据：

```javascript
// 在内存中存储用户数据
{
  "name": "Cache User Data",
  "type": "n8n-nodes-base.set",
  "parameters": {
    "values": {
      "userCache.{{ $json.username }}": "={{ $json }}"
    }
  }
}
```

## 后续步骤

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