Maybe I'm just tired, but I can't figure out how to use the Reddit-API to retrieve stories properly despite staring at the API docs [1] for an hour..
For example if I GET the URL http://www.reddit.com/r/gaming/top.json?limit=5
then I get 5 story elements.
At the bottom it says before : null
and after : "t3_12vgdt"
, which corresponds to the name
property of the last returned story-item.
How to interpret this? And how do I paginate to the next 5 items, items 6 - 10?
[1] referenced here: https://github.com/reddit/reddit/wiki/API
Reddit has a extensive API which allows you to access a lot of the information on reddit in easy to work with json formatting. Most pages on reddit can also be accessed through json by simply adding .
You can get data from any subreddit or Reddit user in JSON format, using Reddit's free and dead-simple API. Just add . json to the end of a Reddit URL: reddit.com/r/worldnews.json.
Many endpoints on reddit use the same protocol for controlling pagination and filtering. These endpoints are called Listings and share five common parameters: after / before , limit , count , and show . Listings do not use page numbers because their content changes so frequently.
You need to add the query parameter after=t3_12vgdt
. Because there is already an existing query parameter, limit=5
, you have to use &
to add the additional parameter.
http://www.reddit.com/r/gaming/top.json?limit=5&after=t3_12vgdt
You'll notice if you use the actual reddit pages (remove the .json
) that this is exactly how it behaves when you click on the next link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With