How to page through top-stories on Reddit?
Asked Answered
T

1

7

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

Truckage answered 9/11, 2012 at 19:56 Comment(0)
T
7

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.

Troposphere answered 9/11, 2012 at 21:11 Comment(1)
"Why was I confused?" Based on your question, I would say because you were tired. Happens to the best of us.Troposphere

© 2022 - 2024 — McMap. All rights reserved.