@kody/reddit
README.md
161 lines · 7.1 KB · Markdown@kody/reddit
Official Reddit logo (#FF4500) from Reddit brand guidelines.
Intent
Give any Kody account reusable, headless Reddit helpers for subreddit metadata, listings, search, user reads, a generic authenticated request escape hatch, and guarded writes (submit post, submit comment, vote). Author identity is always resolved from the connected Reddit account — never hard-coded to a specific username.
This listing is meant to be forked. After you fork, connect your Reddit account and run ./smoke-test on your copy. Do not treat the live @kody/reddit integration as yours.
When To Use
- Verify the saved
redditOAuth integration and read the connected account - Look up a subreddit, listing, search result, user, or post/comment thread
- Call uncommon Reddit OAuth endpoints with
./request - Preview a post, comment, or vote with
dryRun: true, then mutate only afterconfirm: true
Do not use this package as a scraper, a 24/7 bot, or a place to paste access tokens. Jobs are off.
OAuth setup
Reddit is bring-your-own OAuth. There is no built-in Kody Reddit app. Tokens come from the hosted connect page (createAuthenticatedFetch('reddit')). Never paste a client secret or access token into chat.
- Open reddit.com/prefs/apps → create another app….
- Choose web app.
- redirect uri → add exactly
https://kody.codes/connect/oauth(the connect page shows the same value with a copy button). - Note the app’s client id (under the name) and secret (paste them into Kody, not into chat).
- Open this prefilled connect URL while signed in to Kody:
https://kody.codes/connect/oauth?provider=redditFirst-time setup also needs Reddit’s authorize and token URLs. Use this complete prefilled URL when the connection does not exist yet:
https://kody.codes/connect/oauth?provider=reddit&authorizeUrl=https%3A%2F%2Fwww.reddit.com%2Fapi%2Fv1%2Fauthorize&tokenUrl=https%3A%2F%2Fwww.reddit.com%2Fapi%2Fv1%2Faccess_token&apiBaseUrl=https%3A%2F%2Foauth.reddit.com&flow=confidential&tokenExchangeStyle=basic-form&allowedHosts=oauth.reddit.com%2Cwww.reddit.com&dashboardUrl=https%3A%2F%2Fwww.reddit.com%2Fprefs%2Fapps&scopes=identity%20read%20history%20mysubreddits%20submit%20edit%20vote%20save&extraAuthorizeParams=duration%3DpermanentDecoded:
- Redirect / callback:
https://kody.codes/connect/oauth - Authorize:
https://www.reddit.com/api/v1/authorize - Token:
https://www.reddit.com/api/v1/access_token - API base:
https://oauth.reddit.com - Flow:
confidentialwithtokenExchangeStyle=basic-form(HTTP Basic + form body) - Hosts:
oauth.reddit.com,www.reddit.com - Extra authorize param:
duration=permanent(needed for a refresh token) - Scopes:
identity,read,history,mysubreddits,submit,edit,vote,save
- Paste the client id and secret into the Kody form, continue to Reddit, and approve.
- Run Smoke test on the forked package.
Reconnect the same connection with https://kody.codes/connect/oauth?provider=reddit. Kody reuses the saved authorize/token endpoints.
Scopes
| Scope | Used by |
|---|---|
identity | ./smoke-test, ./get-me |
read | listings, search, subreddit about, posts, comments, user about |
history | authenticated user history when requested through ./request |
mysubreddits | subscribed-community reads through ./request |
submit | ./submit-post, ./submit-comment |
edit | edits through ./request |
vote | ./vote |
save | saves through ./request |
./request uses whatever scopes the saved token already has. ./smoke-test does not return the connected username.
Auth / transport
There is no usable public Reddit OpenAPI for the full OAuth surface. This package uses a compact request helper that authenticates with createAuthenticatedFetch('reddit') and sends Reddit’s required User-Agent on every oauth.reddit.com call.
Pass account: '<purpose>' for integration reddit-<purpose> (omit → reddit). Do not hard-code a username in forks.
Smoke test
After connect or reconnect, invoke ./smoke-test in the forked package runtime (not a static import):
import { packages } from 'kody:runtime'
export default async function main() {
return await packages.invoke({
kodyId: 'reddit',
exportName: './smoke-test',
})
}Or import the published package:
import smokeTest from 'kody:@kody/reddit/smoke-test'
export default async function main() {
return await smokeTest()
}Success looks like { ok: true, integration: 'reddit', hasId: true, hasName: true } and does not return the username.
dryRun and writes
Submit and vote helpers never mutate Reddit when dryRun: true. A live write requires a fresh confirm: true after the user approved the exact payload.
import submitPost from 'kody:@kody/reddit/submit-post'
export default async function main() {
return await submitPost({
subreddit: 'test',
title: 'Draft title',
text: 'Draft body',
dryRun: true,
})
}Exports
kody:@kody/reddit— package overview, connect URL, and scopeskody:@kody/reddit/accounts— resolvereddit/reddit-<purpose>kody:@kody/reddit/smoke-test— verify identity access without returning the usernamekody:@kody/reddit/get-me— connected account from/api/v1/mekody:@kody/reddit/get-subreddit— community about pagekody:@kody/reddit/get-listing— front page or subreddit listingkody:@kody/reddit/search— post search, optionally in one subredditkody:@kody/reddit/get-user— user about, submitted, comments, or overviewkody:@kody/reddit/get-post— one post plus commentskody:@kody/reddit/request— authenticated Reddit API request helperkody:@kody/reddit/submit-post— self or link post helper (mutating)kody:@kody/reddit/submit-comment— comment helper (mutating)kody:@kody/reddit/vote— upvote / downvote / clear helper (mutating)
Examples
import getListing from 'kody:@kody/reddit/get-listing'
export default async function main() {
return await getListing({ subreddit: 'programming', sort: 'hot', limit: 5 })
}import search from 'kody:@kody/reddit/search'
export default async function main() {
return await search({ query: 'kody agents', limit: 5 })
}Troubleshooting
- Connect page asks for authorize/token URLs: use the complete first-time URL in OAuth setup.
- HTTP 401 / 403: reconnect at
https://kody.codes/connect/oauth?provider=reddit. Confirm the Reddit app is a web app and the redirect URI is exactlyhttps://kody.codes/connect/oauth. - HTTP 429: Reddit requires a unique User-Agent. This package sends
web:kody.reddit:1.0.0 (https://kody.codes/@kody/reddit). If token exchange itself is blocked, the hosted connect page may need a Reddit-friendly User-Agent — reconnect after that is fixed rather than pasting tokens into chat. redirect_urimismatch: the Reddit app redirect must be exactlyhttps://kody.codes/connect/oauth.- Writes no-op: pass
dryRun: trueto preview, thenconfirm: trueonly after the user approves the exact payload.