hackernews

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Hacker News API

Hacker News API

Use the official Hacker News API via direct
curl
calls to fetch stories, comments, and user data.
Official docs:
https://github.com/HackerNews/API

通过直接调用
curl
来使用官方Hacker News API,以获取故事、评论和用户数据
官方文档:
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/v0

Important: When using
$VAR
in a command that pipes to another command, wrap the command containing
$VAR
in
bash -c '...'
. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.
bash
bash -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
的命令用
bash -c '...'
包裹。由于Claude Code的一个bug,直接使用管道时环境变量会被静默清除。
bash
bash -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
<item-id>
with the actual item ID:
bash
curl -s "https://hacker-news.firebaseio.com/v0/item/<item-id>.json"
Response fields:
FieldDescription
id
Unique item ID
type
story
,
comment
,
job
,
poll
,
pollopt
by
Username of author
time
Unix timestamp
title
Story title (stories only)
url
Story URL (if external link)
text
Content text (Ask HN, comments)
score
Upvote count
descendants
Total comment count
kids
Array of child comment IDs
通过ID获取任意条目的完整详情。将
<item-id>
替换为实际条目ID:
bash
curl -s "https://hacker-news.firebaseio.com/v0/item/<item-id>.json"
响应字段:
字段说明
id
唯一条目ID
type
类型:
story
comment
job
poll
pollopt
by
作者用户名
time
Unix时间戳
title
故事标题(仅故事类型)
url
故事链接(如果是外部链接)
text
内容文本(Ask HN、评论)
score
点赞数
descendants
总评论数
kids
子评论ID数组

8. Get Multiple Stories with Details

8. 获取多个故事的完整详情

Fetch top 5 stories with full details. Replace
<item-id>
with the actual 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个故事的完整详情。将
<item-id>
替换为实际条目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

9. Get Story with Comments

9. 获取故事及其评论

Fetch a story and its top-level comments. Replace
<story-id>
with the actual 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
kids
array, replace
<comment-id>
with the actual comment ID:
bash
curl -s "https://hacker-news.firebaseio.com/v0/item/<comment-id>.json" | jq '{by, text, score}'

获取某个故事及其顶级评论。将
<story-id>
替换为实际故事ID:
bash
curl -s "https://hacker-news.firebaseio.com/v0/item/<story-id>.json" | jq '{title, score, descendants, kids}'
然后对于
kids
数组中的每个评论ID,将
<comment-id>
替换为实际评论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
<username>
with the actual username:
bash
curl -s "https://hacker-news.firebaseio.com/v0/user/<username>.json"
Response fields:
FieldDescription
id
Username
created
Account creation timestamp
karma
User's karma score
about
User bio (HTML)
submitted
Array of item IDs submitted
获取用户详情。将
<username>
替换为实际用户名:
bash
curl -s "https://hacker-news.firebaseio.com/v0/user/<username>.json"
响应字段:
字段说明
id
用户名
created
账户创建时间戳
karma
用户的 karma 分数
about
用户简介(HTML格式)
submitted
用户发布的条目ID数组

11. Get User's Recent Submissions

11. 获取用户近期发布的内容

Fetch a user's recent submissions. Replace
<username>
with the actual 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")"'
done
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) 赞 | \(.title) | \(.url // "Ask HN")"'
done

Find 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)"'
done
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)"'
done

Get 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)"'
done

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)"'
done

API Endpoints Summary

API端点汇总

EndpointDescription
/v0/topstories.json
Top 500 stories
/v0/beststories.json
Best stories
/v0/newstories.json
Newest 500 stories
/v0/askstories.json
Ask HN stories
/v0/showstories.json
Show HN stories
/v0/jobstories.json
Job postings
/v0/item/{id}.json
Item details
/v0/user/{id}.json
User profile
/v0/maxitem.json
Current max item ID
/v0/updates.json
Changed items/profiles

端点说明
/v0/topstories.json
前500个热门故事
/v0/beststories.json
优质故事
/v0/newstories.json
最新500个故事
/v0/askstories.json
Ask HN帖子
/v0/showstories.json
Show HN帖子
/v0/jobstories.json
招聘帖子
/v0/item/{id}.json
条目详情
/v0/user/{id}.json
用户资料
/v0/maxitem.json
当前最大条目ID
/v0/updates.json
更新的条目/资料

Guidelines

使用指南

  1. No rate limits documented: But be respectful, add delays for bulk fetching
  2. Use jq for filtering: Filter JSON responses to extract needed data
  3. Cache results: Stories don't change frequently, cache when possible
  4. Batch requests carefully: Each item requires a separate API call
  5. Handle nulls: Some fields may be null or missing (e.g.,
    url
    for Ask HN)
  6. Unix timestamps: All times are Unix timestamps, convert as needed
  1. 无文档说明的速率限制:但请保持克制,批量获取时添加延迟
  2. 使用jq进行过滤:过滤JSON响应以提取所需数据
  3. 缓存结果:故事不会频繁变化,尽可能缓存
  4. 谨慎批量请求:每个条目需要单独的API调用
  5. 处理空值:部分字段可能为空或缺失(如Ask HN的
    url
  6. Unix时间戳:所有时间均为Unix时间戳,按需转换