Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to page through top-stories on Reddit?

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

like image 257
scrrr Avatar asked Nov 09 '12 19:11

scrrr


People also ask

Does Reddit have an 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 .

How do I get Reddit JSON?

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.

What is a listing in Reddit?

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.


1 Answers

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.

like image 138
bboe Avatar answered Oct 02 '22 17:10

bboe