开发者

REDDIT Page 3 of reddit json

From 开发者_JS百科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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜