Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reddit api paging : before is always null

Tags:

api

reddit

Im using reddit api and i want to paginate results , after works as expected but before is returned 'null' for any of these queries

{modhash: "", children: Array[26], after: "t3_1q9s6e", before: null}

http://www.reddit.com/r/all/new.json?limit=100&
http://www.reddit.com/r/all/new.json?limit=100&after=t3_1qa3v3
http://www.reddit.com/r/all/new.json?limit=30&after=t3_1qa3v3

Why is the before always returned null ? is it a bug or am i missing something

like image 311
Rana Deep Avatar asked Nov 10 '13 01:11

Rana Deep


People also ask

What is the Reddit API’s rate limit?

The Reddit API’s rate limit is up to 60 requests per minute. It allows a request to up to 100 items at once. If you have less than 100 items to request, you can do it all at once. For more than 100 items, you need to make multiple requests, making sure that you don’t go over the 60 requests per minute as per the rules.

How to make a simple request to Reddit API?

Making a simple request to the API, Using the two most popular wrappers: PRAW and Pushshift. Posting to a Subreddit. At the end of this tutorial, you’ll know everything that you need to know about the Reddit API and how to do the examples below. Here are two things that you will be able to do after reading this guide.

How to use Reddit API with Python?

Reddit API with Python (Complete Guide) 1 How to get your credentials and to use the API. 2 Making a simple request to the API, 3 Using the two most popular wrappers: PRAW and Pushshift. 4 Extracting data 5 Posting to a Subreddit. More ...

How to get content from the Reddit API using JSON?

There are various types, but JSON is almost an industry standard nowadays. Grab the content as follows: As far as JSON response of Reddit API is concerned, the response dictionary is usually very loaded. The first thing you can check is the dictionary keys. After the keys, we can grab the piece we want, and move progressively.


1 Answers

As described in the docs, try specifying a count:

http://www.reddit.com/r/all/new.json?limit=30&after=t31qa3v3&count=10

Basically what happens is that reddit needs to know how many posts you've just viewed in order to determine what the starting point of the "previous" listing is. So if you use the above example, you're telling the api to start on the article that comes directly after t31qa3v3, display 30 new resuults, and give you the id of the article 10 spots before t31qa3v3 to act as your before value. If you don't include the count, it won't know what to use hence the null.

like image 117
Sinaesthetic Avatar answered Sep 21 '22 11:09

Sinaesthetic