Search code examples
phpjsonapireddit

REDDIT Page 3 of reddit json


From the Reddit api, it says it is possible to get the json of a page. I can do this for the front page, but how do I do I get the json for the third page without visiting the second page?

Is it even possible?

I am using php.


Solution

  • Use the last item from the previous page. Abridged/simplified C# example of getting "new items" pages (code that parses the previous page passes lastItem back to the method that gets the next page):

    public static string k_baseUrlFormat = "http://www.reddit.com/r/{0}/new/.json?sort=new{1}";
    public static string k_moreFormat = "&after={0}";
    
    // [snip]
    
            string more = "";
            if ( !string.IsNullOrEmpty( lastItem ) )
            {
                more = string.Format( k_moreFormat, lastItem );
            }
            string url = string.Format( k_baseUrlFormat, subreddit, more );   
    

    lastItem is item id including type ID, that looks like t3_g6a4s. You can use other parameters for different stuff in the same way as w/standard web requests for pages.