Search code examples
phpapireddit

Reddit API: Return more than 100 results


I am using PHP to fetch the .json for a certain subreddit but I want to only pull the results from the past day (and this sometimes needs to pull more than the maximum of 100 results). I was thinking of just pulling the max 600 and filtering on created_utc but the Reddit API limits me to 100 results.

How can I pull the results only from the past day (or at least pull more than 100 results).

Here is my relevant code

$json = file_get_contents('https://www.reddit.com/r/[SUBREDDIT]/new.json?limit=600');

Solution

  • Probably your only solution is to make multiple requests to the api.

    So basically in your JSON: (example)

    "after": "t3_1oi5fb", "before": null

    t3_1oi5fb would be the fullname of a thing, refer to the documentation for more info here: https://www.reddit.com/dev/api

    Remember that the API request limit is 30 requests in 60 seconds though.