scraping-tweets-from-account
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseScraping Tweets from an Account
抓取账号推文
Exports the full tweet history of any public Twitter/X account. Returns the raw timeline dataset including replies and media.
导出任意公开Twitter/X账号的完整推文历史。返回包含回复和媒体内容的原始时间线数据集。
Prerequisites
前置条件
- environment variable set
APIFY_TOKEN - Optional: Apify MCP server installed
- 设置环境变量
APIFY_TOKEN - 可选:安装Apify MCP服务器
Inputs
输入参数
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| array | ✅ | | Twitter advanced search queries (e.g. |
| string | Optional | | Sort order: |
| string | Optional | — | ISO 639-1 language code (e.g. |
| number | Optional | Unlimited | Maximum tweets to return |
| boolean | Optional | | Only tweets from verified users |
| boolean | Optional | | Only Twitter Blue subscribers |
| boolean | Optional | | Only tweets with images |
| boolean | Optional | | Only tweets with videos |
| boolean | Optional | | Only quote tweets |
| string | Optional | — | Filter to a specific author handle |
| string | Optional | — | Tweets replying to a specific handle |
| string | Optional | — | Tweets mentioning a specific handle |
| string | Optional | — | Tweets near a location |
| string | Optional | — | Radius around geotaggedNear |
| string | Optional | — | Lat/lng + radius string |
| string | Optional | — | Tweets tagged with a place |
| number | Optional | — | Minimum retweet count |
| number | Optional | — | Minimum like count |
| number | Optional | — | Minimum reply count |
| string | Optional | — | Tweets after this date (YYYY-MM-DD) |
| string | Optional | — | Tweets before this date (YYYY-MM-DD) |
| boolean | Optional | | Add the matched search term to each tweet |
| string | Optional | — | JavaScript function to transform each output object |
| 参数 | 类型 | 是否必填 | 默认值 | 说明 |
|---|---|---|---|---|
| 数组 | ✅ | | Twitter高级搜索查询(例如 |
| 字符串 | 可选 | | 排序方式: |
| 字符串 | 可选 | — | ISO 639-1语言代码(例如 |
| 数字 | 可选 | 无限制 | 返回的最大推文数量 |
| 布尔值 | 可选 | | 仅返回认证用户的推文 |
| 布尔值 | 可选 | | 仅返回Twitter Blue订阅者的推文 |
| 布尔值 | 可选 | | 仅返回包含图片的推文 |
| 布尔值 | 可选 | | 仅返回包含视频的推文 |
| 布尔值 | 可选 | | 仅返回引用推文 |
| 字符串 | 可选 | — | 过滤特定作者的账号 |
| 字符串 | 可选 | — | 回复特定账号的推文 |
| 字符串 | 可选 | — | 提及特定账号的推文 |
| 字符串 | 可选 | — | 特定地点附近的推文 |
| 字符串 | 可选 | — | |
| 字符串 | 可选 | — | 纬度/经度 + 半径字符串 |
| 字符串 | 可选 | — | 标记特定地点的推文 |
| 数字 | 可选 | — | 最小转发数 |
| 数字 | 可选 | — | 最小点赞数 |
| 数字 | 可选 | — | 最小回复数 |
| 字符串 | 可选 | — | 该日期之后的推文(格式:YYYY-MM-DD) |
| 字符串 | 可选 | — | 该日期之前的推文(格式:YYYY-MM-DD) |
| 布尔值 | 可选 | | 为每条推文添加匹配的搜索关键词 |
| 字符串 | 可选 | — | 用于转换每个输出对象的JavaScript函数 |
Workflow
工作流程
Progress:
- [ ] Step 1: Confirm account is public
- [ ] Step 2: Run tweet-scraper
- [ ] Step 3: Poll for SUCCEEDED
- [ ] Step 4: Fetch and deliver datasetProgress:
- [ ] Step 1: Confirm account is public
- [ ] Step 2: Run tweet-scraper
- [ ] Step 3: Poll for SUCCEEDED
- [ ] Step 4: Fetch and deliver datasetStep 1: Validate Input
步骤1:验证输入
Strip from username if present. Do not attempt to scrape private accounts — the actor will return 0 results.
@如果用户名包含则去除。请勿尝试抓取私人账号——该Actor将返回0条结果。
@Step 2: Run the Actor
步骤2:运行Actor
Recommended — run_actor.js (handles waiting, output, and file saving automatically):
bash
undefined推荐方式——run_actor.js(自动处理等待、输出和文件保存):
bash
undefinedQuick answer (prints table to chat)
Quick answer (prints table to chat)
node scripts/run_actor.js
--actor "apidojo~tweet-scraper"
--input '{"param": "value"}'
--actor "apidojo~tweet-scraper"
--input '{"param": "value"}'
node scripts/run_actor.js
--actor "apidojo~tweet-scraper"
--input '{"param": "value"}'
--actor "apidojo~tweet-scraper"
--input '{"param": "value"}'
Save as CSV
Save as CSV
node scripts/run_actor.js
--actor "apidojo~tweet-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.csv --format csv
--actor "apidojo~tweet-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.csv --format csv
node scripts/run_actor.js
--actor "apidojo~tweet-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.csv --format csv
--actor "apidojo~tweet-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.csv --format csv
Save as JSON
Save as JSON
node scripts/run_actor.js
--actor "apidojo~tweet-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.json --format json
--actor "apidojo~tweet-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.json --format json
> `APIFY_TOKEN` must be set in environment or `.env` file.
**If Apify MCP is available:**Tool: apify:run-actor
Actor: "apidojo~tweet-scraper"
Input:
{
"twitterHandles": ["<handle>"],
"maxItems": 200,
"sort": "Latest"
}
**REST API fallback:**
```bash
curl -X POST \
"https://api.apify.com/v2/acts/apidojo~tweet-scraper/runs?token=$APIFY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"twitterHandles": ["<handle>"], "maxItems": 200, "sort": "Latest"}'Save as . Poll until :
idRUN_IDstatus = SUCCEEDEDbash
curl "https://api.apify.com/v2/actor-runs/$RUN_ID?token=$APIFY_TOKEN" | grep '"status"'Fetch results:
bash
curl "https://api.apify.com/v2/actor-runs/$RUN_ID/dataset/items?token=$APIFY_TOKEN&format=json"node scripts/run_actor.js
--actor "apidojo~tweet-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.json --format json
--actor "apidojo~tweet-scraper"
--input '{"param": "value"}'
--output YYYY-MM-DD_results.json --format json
> `APIFY_TOKEN`必须在环境变量或`.env`文件中配置。
**如果Apify MCP可用:**Tool: apify:run-actor
Actor: "apidojo~tweet-scraper"
Input:
{
"twitterHandles": ["<handle>"],
"maxItems": 200,
"sort": "Latest"
}
**REST API备选方案:**
```bash
curl -X POST \
"https://api.apify.com/v2/acts/apidojo~tweet-scraper/runs?token=$APIFY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"twitterHandles": ["<handle>"], "maxItems": 200, "sort": "Latest"}'保存返回的为,轮询直到:
idRUN_IDstatus = SUCCEEDEDbash
curl "https://api.apify.com/v2/actor-runs/$RUN_ID?token=$APIFY_TOKEN" | grep '"status"'获取结果:
bash
curl "https://api.apify.com/v2/actor-runs/$RUN_ID/dataset/items?token=$APIFY_TOKEN&format=json"Step 3: Handle Edge Cases
步骤3:处理边缘情况
- 0 results: Account may be private, suspended, or handle misspelled. Report to user.
- Fewer results than expected: Account may have fewer public tweets than requested. Return what is available.
- Protected account: Actor returns empty — inform user the account is private.
- 0条结果:账号可能是私人账号、已被封禁,或用户名拼写错误。请告知用户。
- 结果数量少于预期:账号的公开推文数量可能少于请求的数量。返回现有可用内容即可。
- 受保护账号:Actor将返回空结果——告知用户该账号为私人账号。
Output Format
输出格式
undefinedundefinedTweet Timeline: @<username>
Tweet Timeline: @<username>
Tweets collected: N | Includes replies: YES/NO | Includes retweets: YES/NO
| Tweet ID | Text (truncated) | Likes | Retweets | Replies | Media | Timestamp |
|---|---|---|---|---|---|---|
| ... | ... | ... | ... | ... | ... | ... |
Full dataset: N rows × 12 fields
Available fields: id, text, likeCount, retweetCount, replyCount, quoteCount,
isReply, isRetweet, media, tweetUrl, lang, createdAt
undefinedTweets collected: N | Includes replies: YES/NO | Includes retweets: YES/NO
| Tweet ID | Text (truncated) | Likes | Retweets | Replies | Media | Timestamp |
|---|---|---|---|---|---|---|
| ... | ... | ... | ... | ... | ... | ... |
Full dataset: N rows × 12 fields
Available fields: id, text, likeCount, retweetCount, replyCount, quoteCount,
isReply, isRetweet, media, tweetUrl, lang, createdAt
undefinedTroubleshooting
故障排除
0 results for a known public account: Try again — Twitter may rate-limit intermittently.
Missing older tweets: Twitter API limits historical access; very old tweets may not be available.
Timeout: Reduce to 500 max per run.
maxItems已知公开账号返回0条结果:重试即可——Twitter可能会间歇性触发速率限制。
缺少旧推文:Twitter API对历史数据访问有限制;非常早期的推文可能无法获取。
超时:将减少至每次运行最多500条。
maxItems