hackernews
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHacker News API
Hacker News API
Use the official Hacker News API via direct calls to fetch stories, comments, and user data.
curlOfficial docs:https://github.com/HackerNews/API
通过直接调用来使用官方Hacker News API,以获取故事、评论和用户数据。
curl官方文档:https://github.com/HackerNews/API
When to Use
适用场景
Use this skill when you need to:
- Fetch top/best/new stories from Hacker News
- Get story details including title, URL, score, comments
- Retrieve comments and discussion threads
- Look up user profiles and their submissions
- Monitor trending tech topics and discussions
在以下场景中使用该技能:
- 从Hacker News获取热门/优质/最新故事
- 获取故事详情,包括标题、链接、点赞数、评论
- 获取评论及讨论线程
- 查询用户资料及其发布的内容
- 监控热门技术话题与讨论
Prerequisites
前置条件
No API key required! The Hacker News API is completely free and open.
Base URL:
https://hacker-news.firebaseio.com/v0Important: When usingin a command that pipes to another command, wrap the command containing$VARin$VAR. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"'
无需API密钥! Hacker News API完全免费且开放。
基础URL:
https://hacker-news.firebaseio.com/v0重要提示: 当在包含管道的命令中使用时,请将包含$VAR的命令用$VAR包裹。由于Claude Code的一个bug,直接使用管道时环境变量会被静默清除。bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"'
How to Use
使用方法
1. Get Top Stories
1. 获取热门故事
Fetch IDs of the current top 500 stories:
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/topstories.json"' | jq '.[:10]'获取当前前500个热门故事的ID:
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/topstories.json"' | jq '.[:10]'2. Get Best Stories
2. 获取优质故事
Fetch the best stories (highest voted over time):
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/beststories.json"' | jq '.[:10]'获取长期点赞数最高的优质故事:
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/beststories.json"' | jq '.[:10]'3. Get New Stories
3. 获取最新故事
Fetch the newest stories:
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/newstories.json"' | jq '.[:10]'获取最新发布的故事:
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/newstories.json"' | jq '.[:10]'4. Get Ask HN Stories
4. 获取Ask HN帖子
Fetch "Ask HN" posts:
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/askstories.json"' | jq '.[:10]'获取“Ask HN”类帖子:
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/askstories.json"' | jq '.[:10]'5. Get Show HN Stories
5. 获取Show HN帖子
Fetch "Show HN" posts:
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/showstories.json"' | jq '.[:10]'获取“Show HN”类帖子:
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/showstories.json"' | jq '.[:10]'6. Get Job Stories
6. 获取招聘帖子
Fetch job postings:
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/jobstories.json"' | jq '.[:10]'获取招聘类帖子:
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/jobstories.json"' | jq '.[:10]'Item Details
条目详情
7. Get Story/Comment/Job Details
7. 获取故事/评论/招聘详情
Fetch full details for any item by ID. Replace with the actual item ID:
<item-id>bash
curl -s "https://hacker-news.firebaseio.com/v0/item/<item-id>.json"Response fields:
| Field | Description |
|---|---|
| Unique item ID |
| |
| Username of author |
| Unix timestamp |
| Story title (stories only) |
| Story URL (if external link) |
| Content text (Ask HN, comments) |
| Upvote count |
| Total comment count |
| Array of child comment IDs |
通过ID获取任意条目的完整详情。将替换为实际条目ID:
<item-id>bash
curl -s "https://hacker-news.firebaseio.com/v0/item/<item-id>.json"响应字段:
| 字段 | 说明 |
|---|---|
| 唯一条目ID |
| 类型: |
| 作者用户名 |
| Unix时间戳 |
| 故事标题(仅故事类型) |
| 故事链接(如果是外部链接) |
| 内容文本(Ask HN、评论) |
| 点赞数 |
| 总评论数 |
| 子评论ID数组 |
8. Get Multiple Stories with Details
8. 获取多个故事的完整详情
Fetch top 5 stories with full details. Replace with the actual item ID:
<item-id>bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/topstories.json"' | jq '.[:5][]' | while read id; do
curl -s "https://hacker-news.firebaseio.com/v0/item/${id}.json" | jq '{id, title, score, url, by}'
done获取前5个故事的完整详情。将替换为实际条目ID:
<item-id>bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/topstories.json"' | jq '.[:5][]' | while read id; do
curl -s "https://hacker-news.firebaseio.com/v0/item/${id}.json" | jq '{id, title, score, url, by}'
done9. Get Story with Comments
9. 获取故事及其评论
Fetch a story and its top-level comments. Replace with the actual story ID:
<story-id>bash
curl -s "https://hacker-news.firebaseio.com/v0/item/<story-id>.json" | jq '{title, score, descendants, kids}'Then for each comment ID in the array, replace with the actual comment ID:
kids<comment-id>bash
curl -s "https://hacker-news.firebaseio.com/v0/item/<comment-id>.json" | jq '{by, text, score}'获取某个故事及其顶级评论。将替换为实际故事ID:
<story-id>bash
curl -s "https://hacker-news.firebaseio.com/v0/item/<story-id>.json" | jq '{title, score, descendants, kids}'然后对于数组中的每个评论ID,将替换为实际评论ID:
kids<comment-id>bash
curl -s "https://hacker-news.firebaseio.com/v0/item/<comment-id>.json" | jq '{by, text, score}'User Data
用户数据
10. Get User Profile
10. 获取用户资料
Fetch user details. Replace with the actual username:
<username>bash
curl -s "https://hacker-news.firebaseio.com/v0/user/<username>.json"Response fields:
| Field | Description |
|---|---|
| Username |
| Account creation timestamp |
| User's karma score |
| User bio (HTML) |
| Array of item IDs submitted |
获取用户详情。将替换为实际用户名:
<username>bash
curl -s "https://hacker-news.firebaseio.com/v0/user/<username>.json"响应字段:
| 字段 | 说明 |
|---|---|
| 用户名 |
| 账户创建时间戳 |
| 用户的 karma 分数 |
| 用户简介(HTML格式) |
| 用户发布的条目ID数组 |
11. Get User's Recent Submissions
11. 获取用户近期发布的内容
Fetch a user's recent submissions. Replace with the actual username:
<username>bash
curl -s "https://hacker-news.firebaseio.com/v0/user/<username>.json" | jq '.submitted[:5]'获取用户近期发布的内容。将替换为实际用户名:
<username>bash
curl -s "https://hacker-news.firebaseio.com/v0/user/<username>.json" | jq '.submitted[:5]'Real-time Updates
实时更新
12. Get Max Item ID
12. 获取最大条目ID
Get the current largest item ID (useful for polling new items):
bash
curl -s "https://hacker-news.firebaseio.com/v0/maxitem.json"获取当前最大的条目ID(用于轮询新条目):
bash
curl -s "https://hacker-news.firebaseio.com/v0/maxitem.json"13. Get Changed Items and Profiles
13. 获取更新的条目和资料
Get recently changed items and profiles (for real-time updates):
bash
curl -s "https://hacker-news.firebaseio.com/v0/updates.json"获取最近更新的条目和用户资料(用于实时更新):
bash
curl -s "https://hacker-news.firebaseio.com/v0/updates.json"Practical Examples
实用示例
Fetch Today's Top 10 with Scores
获取今日前10个带点赞数的故事
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/topstories.json"' | jq '.[:10][]' | while read id; do
curl -s "https://hacker-news.firebaseio.com/v0/item/${id}.json" | jq -r '"\(.score) points | \(.title) | \(.url // "Ask HN")"'
donebash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/topstories.json"' | jq '.[:10][]' | while read id; do
curl -s "https://hacker-news.firebaseio.com/v0/item/${id}.json" | jq -r '"\(.score) 赞 | \(.title) | \(.url // "Ask HN")"'
doneFind High-Scoring Stories (100+ points)
查找高赞故事(100+赞)
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/topstories.json"' | jq '.[:30][]' | while read id; do
curl -s "https://hacker-news.firebaseio.com/v0/item/${id}.json" | jq -r 'select(.score >= 100) | "\(.score) | \(.title)"'
donebash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/topstories.json"' | jq '.[:30][]' | while read id; do
curl -s "https://hacker-news.firebaseio.com/v0/item/${id}.json" | jq -r 'select(.score >= 100) | "\(.score) | \(.title)"'
doneGet Latest AI/ML Related Stories
获取最新AI/ML相关故事
bash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/topstories.json"' | jq '.[:50][]' | while read id; do
curl -s "https://hacker-news.firebaseio.com/v0/item/${id}.json" | jq -r 'select(.title | test("AI|GPT|LLM|Machine Learning|Neural"; "i")) | "\(.score) | \(.title)"'
donebash
bash -c 'curl -s "https://hacker-news.firebaseio.com/v0/topstories.json"' | jq '.[:50][]' | while read id; do
curl -s "https://hacker-news.firebaseio.com/v0/item/${id}.json" | jq -r 'select(.title | test("AI|GPT|LLM|Machine Learning|Neural"; "i")) | "\(.score) | \(.title)"'
doneAPI Endpoints Summary
API端点汇总
| Endpoint | Description |
|---|---|
| Top 500 stories |
| Best stories |
| Newest 500 stories |
| Ask HN stories |
| Show HN stories |
| Job postings |
| Item details |
| User profile |
| Current max item ID |
| Changed items/profiles |
| 端点 | 说明 |
|---|---|
| 前500个热门故事 |
| 优质故事 |
| 最新500个故事 |
| Ask HN帖子 |
| Show HN帖子 |
| 招聘帖子 |
| 条目详情 |
| 用户资料 |
| 当前最大条目ID |
| 更新的条目/资料 |
Guidelines
使用指南
- No rate limits documented: But be respectful, add delays for bulk fetching
- Use jq for filtering: Filter JSON responses to extract needed data
- Cache results: Stories don't change frequently, cache when possible
- Batch requests carefully: Each item requires a separate API call
- Handle nulls: Some fields may be null or missing (e.g., for Ask HN)
url - Unix timestamps: All times are Unix timestamps, convert as needed
- 无文档说明的速率限制:但请保持克制,批量获取时添加延迟
- 使用jq进行过滤:过滤JSON响应以提取所需数据
- 缓存结果:故事不会频繁变化,尽可能缓存
- 谨慎批量请求:每个条目需要单独的API调用
- 处理空值:部分字段可能为空或缺失(如Ask HN的)
url - Unix时间戳:所有时间均为Unix时间戳,按需转换