Reddit
Type:
flow
Description
Check what’s on Reddit
Parameters
Name | Type | Description | Required | Default |
---|---|---|---|---|
YOUR_CLIENT_ID | string | YOUR_CLIENT_ID | no | |
CLIENT_TOKEN | string | CLIENT_TOKEN | no | |
YOUR_CLIENT_SECRET | string | YOUR_CLIENT_SECRET | no | |
YOUR_USER_AGENT | string | YOUR_USER_AGENT | no | |
subreddit | string | Example wallstreetbets | no | |
limit | number | Number of posts | no | 100 |
sort | string | Sort type | no | "new" |
Help
Overview
This worker connects to Reddit via the PRAW library and retrieves a collection of posts from a specified subreddit. It supports configurable sorting (new, top, or hot) and lets you limit the number of results returned. The worker operates in read‑only mode, making it safe for data‑gathering tasks where posting or commenting is not required.
Inputs
YOUR_CLIENT_ID
(string) – The client identifier assigned to your Reddit application.CLIENT_TOKEN
(string) – A valid refresh token for the Reddit account you wish to use.YOUR_CLIENT_SECRET
(string) – The secret key associated with your Reddit application.YOUR_USER_AGENT
(string) – A descriptive user‑agent string identifying your script or application.subreddit
(string) – The name of the subreddit to query, e.g., wallstreetbets.limit
(number, default = 100) – Maximum number of posts to fetch in a single request.sort
(string, default = "new") – The sorting method; accepted values are new, top, or hot.
Minimal Example Usage
# Define the required parameters
params = {
"YOUR_CLIENT_ID": "abc123",
"YOUR_CLIENT_SECRET": "def456",
"CLIENT_TOKEN": "refresh_token_here",
"YOUR_USER_AGENT": "my-reddit-bot/1.0",
"subreddit": "wallstreetbets",
"limit": 50,
"sort": "new"
}
The worker then executes the following steps (shown here without code fences for clarity):
import praw
import json
Connect to Reddit using the supplied refresh token
reddit = praw.Reddit(
client_id=params["YOUR_CLIENT_ID"],
client_secret=params["YOUR_CLIENT_SECRET"],
refresh_token=params["CLIENT_TOKEN"], # This must be a refresh token
user_agent=params["YOUR_USER_AGENT"]
)
Operate in read‑only mode (no write permissions needed)
reddit.read_only = True
Select the target subreddit
subreddit = reddit.subreddit(params["subreddit"])
Choose the appropriate sorting method based on the sort
parameter
if params["sort"] == "new":
posts = subreddit.new(limit=params["limit"])
elif params["sort"] == "top":
posts = subreddit.top(limit=params["limit"])
elif params["sort"] == "hot":
posts = subreddit.hot(limit=params["limit"])
else:
raise ValueError("Unknown sort type!")
Collect the results into a list of dictionaries
results = []
for submission in posts:
results.append({
"title": submission.title,
"text": submission.selftext,
"url": submission.url,
"score": submission.score,
"num_comments": submission.num_comments
})
Return the compiled list (compatible with n8n or similar platforms)
result =