5

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

Rana Deep
  • 617
  • 7
  • 19

1 Answers1

15

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.

Sinaesthetic
  • 11,426
  • 28
  • 107
  • 176