reddit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Call the Reddit API (OAuth endpoints) with
curl + jq
. The user's bearer token is in
$REDDIT_TOKEN
. Every call MUST send a
User-Agent
header
or Reddit returns
429
. Use the OAuth host
https://oauth.reddit.com
.
bash
UA="web:cloud.acedata.connectors:v1.0 (by /u/acedatacloud)"
Errors are JSON; a submit returns
{"json":{"errors":[...], "data":{...}}}
— if
errors
is non-empty, show them verbatim.
401
→ token expired, re-connect.
Always start by confirming identity:
bash
curl -sS -H "Authorization: Bearer $REDDIT_TOKEN" -H "User-Agent: $UA" \
  "https://oauth.reddit.com/api/v1/me" | jq '{name, total_karma, link_karma}'
使用
curl + jq
调用Reddit API(OAuth端点)。用户的Bearer令牌存储在
$REDDIT_TOKEN
中。每一次调用都必须发送
User-Agent
请求头
,否则Reddit会返回
429
错误。使用OAuth主机
https://oauth.reddit.com
bash
UA="web:cloud.acedata.connectors:v1.0 (by /u/acedatacloud)"
错误信息为JSON格式;提交操作会返回
{"json":{"errors":[...], "data":{...}}}
——如果
errors
不为空,请直接显示这些错误信息。
401
错误表示令牌过期,需要重新连接。
始终先确认身份:
bash
curl -sS -H "Authorization: Bearer $REDDIT_TOKEN" -H "User-Agent: $UA" \
  "https://oauth.reddit.com/api/v1/me" | jq '{name, total_karma, link_karma}'

Submit a post

提交帖子

Confirm the subreddit + title + body with the user first.
sr
is the subreddit name WITHOUT the
r/
prefix.
bash
undefined
请先与用户确认子版块+标题+正文内容。
sr
是子版块名称,不要包含
r/
前缀。
bash
undefined

Self (text) post: kind=self + text. Link post: kind=link + url.

纯文本帖子:kind=self + text。链接帖子:kind=link + url。

curl -sS -X POST "https://oauth.reddit.com/api/submit"
-H "Authorization: Bearer $REDDIT_TOKEN" -H "User-Agent: $UA"
--data-urlencode "sr=test"
--data-urlencode "kind=self"
--data-urlencode "title=My title"
--data-urlencode "text=My self-post body in markdown"
--data-urlencode "api_type=json"
| jq '.json | {errors, url: .data.url, id: .data.id}'

For a link post:

```bash
curl -sS -X POST "https://oauth.reddit.com/api/submit" \
  -H "Authorization: Bearer $REDDIT_TOKEN" -H "User-Agent: $UA" \
  --data-urlencode "sr=test" --data-urlencode "kind=link" \
  --data-urlencode "title=My title" --data-urlencode "url=https://example.com" \
  --data-urlencode "api_type=json" | jq '.json'
curl -sS -X POST "https://oauth.reddit.com/api/submit"
-H "Authorization: Bearer $REDDIT_TOKEN" -H "User-Agent: $UA"
--data-urlencode "sr=test"
--data-urlencode "kind=self"
--data-urlencode "title=My title"
--data-urlencode "text=My self-post body in markdown"
--data-urlencode "api_type=json"
| jq '.json | {errors, url: .data.url, id: .data.id}'

如果是链接帖子:

```bash
curl -sS -X POST "https://oauth.reddit.com/api/submit" \
  -H "Authorization: Bearer $REDDIT_TOKEN" -H "User-Agent: $UA" \
  --data-urlencode "sr=test" --data-urlencode "kind=link" \
  --data-urlencode "title=My title" --data-urlencode "url=https://example.com" \
  --data-urlencode "api_type=json" | jq '.json'

Read my submissions

查看我的已提交内容

bash
curl -sS -H "Authorization: Bearer $REDDIT_TOKEN" -H "User-Agent: $UA" \
  "https://oauth.reddit.com/user/USERNAME/submitted?limit=10" \
  | jq '.data.children[] | .data | {title, subreddit, ups, num_comments, permalink}'
bash
curl -sS -H "Authorization: Bearer $REDDIT_TOKEN" -H "User-Agent: $UA" \
  "https://oauth.reddit.com/user/USERNAME/submitted?limit=10" \
  | jq '.data.children[] | .data | {title, subreddit, ups, num_comments, permalink}'

Gotchas

注意事项

  • User-Agent is mandatory on every request — omitting it →
    429
    .
  • Many subreddits gate posting on account age / karma / flair; a submit can return
    errors
    like
    [["SUBREDDIT_NOTALLOWED", ...]]
    — surface it and try
    r/test
    to validate the flow.
  • Respect rate limits: read the
    X-Ratelimit-Remaining
    response header; space out bulk submits.
  • Use
    r/test
    as a safe target when validating that the connection works.
  • 每次请求都必须携带User-Agent——省略它会返回
    429
    错误。
  • 许多子版块对发帖有账号时长/ karma值/ flair标识的限制;提交操作可能会返回类似
    [["SUBREDDIT_NOTALLOWED", ...]]
    的错误信息——请显示该错误,并尝试使用
    r/test
    子版块来验证流程是否正常。
  • 遵守速率限制:读取响应头中的
    X-Ratelimit-Remaining
    字段;批量提交时请间隔执行。
  • 验证连接是否正常时,请使用
    r/test
    作为安全测试目标。

Record the output

记录输出结果

After you successfully publish and obtain the live result URL, call the built-in
publish_artifact
tool ONCE so the user can track this deliverable in My Outputs:
publish_artifact(kind="message", channel="reddit", title="<title>", url="<the REAL returned URL>", status="delivered")
Use the real returned URL — never fabricate one. Call it once per published item, only after delivery is confirmed; skip it (or use
status="failed"
) if publishing failed. See
_shared/artifacts.md
.
成功发布并获取到有效的结果URL后,调用内置的
publish_artifact
工具一次,以便用户可以在我的输出中跟踪该交付成果:
publish_artifact(kind="message", channel="reddit", title="<title>", url="<the REAL returned URL>", status="delivered")
请使用实际返回的URL——切勿伪造。每发布一个内容调用一次该工具,且仅在确认发布成功后调用;如果发布失败,请跳过调用(或使用
status="failed"
)。详情请查看
_shared/artifacts.md