Search code examples
pythonapireddit

Getting incorrect top listing from Reddit API


I've been trying to retrieve the top posts from a subreddit but the listing I get back isn't right. For example if I request: http://www.reddit.com/r/cleveland/top.json?limit=100 I only get back 3 posts.

Edit: here is the code:

content = loads(decode(urlopen(Request('http://www.reddit.com/r/'
                        + subreddit + '/top.json?limit=100', 
          headers={'User-Agent': 'melonbot 1.0 (by /u/Melonus)'})).read()))

Solution

  • Your request is returning the correct results for the page you are requesting.

    The default view for https://www.reddit.com/r/*subreddit*/top/ is the past 24 hours. Currently, /r/Cleveland/top is has 3 posts on this page.

    Reddit screenshot

    The full documentation of the Reddit api is available here: https://www.reddit.com/dev/api.

    The parameter you want is: t=all. With the full request being:

    https://www.reddit.com/r/Cleveland/top/?sort=top&t=all

    As far as I can tell, this will bring back at most 50 results.