subredditstringbắt buộc
Subreddit name without the r/ prefix (e.g. 'Fitness').
https://api.sandbase.ai/v1/api/reddit/subreddit-searchSearch posts within a single subreddit by query, sort, and timeframe.
Đầu ra của bạn sẽ xuất hiện ở đây
Hoàn tất đầu vào, rồi nhấp Run.
Returns Reddit posts from one subreddit that match a search query. It needs a subreddit name without the r/ prefix, and it accepts an optional query, sort and timeframe.
score or numComments to see which threads got the most attention.new.curl -X POST "https://api.sandbase.ai/v1/api/reddit/subreddit-search" \
-H "Authorization: Bearer $SANDBASE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "push ups", "subreddit": "Fitness"}'
The result is returned in outputs[0].data.
| Name | Type | Required | Description |
|---|---|---|---|
subreddit | string | Yes | Subreddit name without the r/ prefix (e.g. 'Fitness'). |
cursor | string | No | Optional pagination token from a previous response. Include nextCursor in requireFields on the first request to make sure a source that supports pagination serves it. |
query | string | No | Optional search query to match posts (e.g. 'push ups'). |
requireFields | array | No | Optional; omit it and routing is unchanged, with the cheapest source serving. Name the output fields this request must be able to return, for example nextCursor or selftext, and it is served only by a source that ret |
sort | string | No | Optional sort order: relevance, hot, top, new, comments. |
timeframe | string | No | Optional time filter: all, year, month, week, day, hour. |
Real response for the request above, trimmed: lists keep their first item and long strings are cut.
{
"data": {
"nextCursor": "cur_vSRO4dkJp_Wni4NIHlJvKQ",
"posts": [
{
"author": "Yea_Red",
"authorId": "j6hq9",
"createdUtc": 1428859519,
"id": "32cksu",
"nsfw": false,
"numComments": 528,
"permalink": "/r/Fitness/comments/32cksu/how_much_will_pushups_help_my_chest/",
"score": 2003,
"selftext": "I try to do 100 a day. Is this doing anything for me, or should I just focus on …",
"subreddit": "Fitness",
"title": "How much will push-ups help my chest?",
"url": "https://www.reddit.com/r/Fitness/comments/32cksu/how_much_will_pushups_help_my_c…"
}
]
},
"found": true
}
| Field | Meaning |
|---|---|
data.posts[].title | Title of the post. |
data.posts[].selftext | Body text of the post. Long text may be cut, and link posts may have none. |
data.posts[].score | Score of the post. |
data.posts[].numComments | Number of comments on the post. |
data.posts[].author / data.posts[].authorId | Username and ID of the post author. |
data.posts[].createdUtc | Creation time of the post as a Unix timestamp in seconds (UTC). |
data.posts[].id | Short ID of the post, such as 32cksu. |
data.posts[].permalink / data.posts[].url | Path and full URL of the post on Reddit. |
data.posts[].nsfw | true if the post is marked NSFW. |
data.nextCursor | Token to pass as cursor to get the next page of results. |
For a Python request example that keeps the search and comment parameters separate, follow the community-research tutorial.
Fitness.nextCursor to requireFields on the first request. Then send the returned data.nextCursor as cursor on the next call.selftext, isArchived or isLocked to requireFields if you need those fields on every post.Billed at the actual cost of each call, about $0.00035 for the request above. Failed calls are not charged.
Bắt đầu xây dựng
Endpoint API của nền tảng với xác thực và theo dõi mức sử dụng thống nhất.
curl -X POST "https://api.sandbase.ai/v1/api/reddit/subreddit-search" \
-H "Authorization: Bearer $SANDBASE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "push ups",
"subreddit": "Fitness"
}'Đặt SandBase API key của bạn trong môi trường máy chủ. Các request sử dụng xác thực Bearer.
export SANDBASE_API_KEY="YOUR_API_KEY"Giữ key của bạn trên máy chủ. Không hiển thị trong mã chạy trên trình duyệt.
subredditstringbắt buộcSubreddit name without the r/ prefix (e.g. 'Fitness').
sortstringOptional sort order: relevance, hot, top, new, comments.
Giá trị có thể dùng: relevance, hot, top, new, comments
querystringOptional search query to match posts (e.g. 'push ups').
cursorstringOptional pagination token from a previous response. Include `nextCursor` in requireFields on the first request to make sure a source that supports pagination serves it.
timeframestringOptional time filter: all, year, month, week, day, hour.
Giá trị có thể dùng: all, year, month, week, day, hour
requireFieldsarrayOptional; omit it and routing is unchanged, with the cheapest source serving. Name the output fields this request must be able to return, for example `nextCursor` or `selftext`, and it is served only by a source that returns every one of them. Fields you do not name are still returned whenever the serving source has them. This can raise your price: when the cheapest source cannot return a named field, a dearer source serves, and you are quoted and charged its price. Name `nextCursor` only if you will fetch more than the first page: when you leave it out, a cheaper source that cannot paginate may serve the request, and its nextCursor is null, so there is no next page to ask for. A named field can still be absent on a post that genuinely lacks it. Naming a combination that no single source returns together is refused as invalid input, with no charge. On a paginated walk it applies to the first page only; later pages stay with the source that page chose, at the price it was quoted.
Đây là phản hồi ví dụ đã lưu cho API này; không có request thực nào được gửi khi xem mục này.
Chưa có phản hồi đã lưu nào được công bố. Chạy API trong Playground để xem phản hồi.
Khám phá thêm
| API | Giá | Phản hồi |
|---|---|---|
Reddit Subreddit SearchAPI này Reddit | Từ $0.00035 mỗi lần gọi | JSON |
Reddit | $0.001 mỗi lần gọi | JSON |
Reddit | $0.001 mỗi lần gọi | JSON |
Reddit | $0.001 mỗi lần gọi | JSON |
Reddit | $0.001 mỗi lần gọi | JSON |
Reddit | $0.001 mỗi lần gọi | JSON |
Câu hỏi
Gửi yêu cầu POST đến https://api.sandbase.ai/v1/api/reddit/subreddit-search với khóa API SandBase của bạn trong tiêu đề Authorization (Bearer) và các tham số trong phần thân JSON. Bạn cũng có thể thử trực tiếp trong Playground trên trang này mà không cần viết code.
Từ $0.00035 mỗi lần gọi, được tính từ số dư SandBase của bạn. Bạn chỉ bị tính phí cho các lần gọi bạn thực hiện; không có gói đăng ký.
Bắt buộc: subreddit (string). Tùy chọn: sort (một trong số relevance, hot, top, new, comments), query (string), cursor (string), timeframe (một trong số all, year, month, week, day, hour) và requireFields (array). Bảng Parameters và Playground trên trang này liệt kê mọi trường.
Phản hồi JSON được trả về trong cùng một yêu cầu HTTP (đồng bộ). README trên trang này có ví dụ phản hồi.
Không. Reddit Subreddit Search chạy thông qua SandBase, nên chỉ cần một API key SandBase là đủ cho endpoint này và mọi API cùng model khác trong danh mục. Bạn không cần đăng ký riêng để có quyền truy cập API của Reddit.
Truyền tên cộng đồng không có r/ vào subreddit, và đặt cụm tìm kiếm vào query. Endpoint này chấp nhận sort và timeframe; hãy dùng các giá trị được liệt kê thay vì tên tham số của Reddit API chính thức. Các endpoint Keyword Search và Dynamic Search của ứng dụng có các trường yêu cầu khác nhau.
Nếu bạn cần phân trang, hãy yêu cầu nextCursor trong requireFields ở lần gọi đầu tiên và kiểm tra giá được đặt trong ngoặc kép của nó: yêu cầu trường này có thể chọn nguồn đắt hơn. Hãy truyền đầy đủ data.nextCursor trả về làm cursor cho trang tiếp theo. Các trang sau vẫn dùng nguồn đã chọn cho trang đầu tiên. Nếu không có yêu cầu này, một nguồn rẻ hơn có thể không trả về phần tiếp nối. Một trường được yêu cầu vẫn có thể vắng mặt ở một bài đăng thực sự không có nó. Đừng dùng lại cursor rút gọn từ ví dụ trong tài liệu.
Không. Tài liệu tham chiếu cho phép selftext bị thiếu hoặc bị rút gọn, và kết quả tìm kiếm chỉ là một mẫu chứ không phải kho lưu trữ cuộc thảo luận đầy đủ. Hãy mở bài đăng đã chọn và dùng endpoint Post Comments với URL của nó khi bạn cần các phản hồi. Đừng coi tiêu đề, đoạn trích hay score là phản hồi sản phẩm đã được xác minh.