开发者

Getting NEW posts from a subreddit in JSON

How would I go abo开发者_JS百科ut getting the new posts of a subreddit in JSON? Just tacking on .json to the url (http://www.reddit.com/r/SOME_SUBREDDIT/new.json) returns the following:

{
    kind: "Listing"
    -
    data: {
        modhash: ""
        children: [ ]
        after: null
        before: null
    }
}

The children array doesn't contain any posts. I've come to find that http://www.reddit.com/r/SOME_SUBREDDIT/new actually routes to new?sort=rising when what I need is new?sort=new.

and /new?sort=new.json of course wont work.


The .json modifier should be put at the end of the path component, not the entire URL. The URL you're looking for is:

http://www.reddit.com/r/subreddit/new.json?sort=new


If you are interested in getting a realtime stream of all of the Reddit new post, Pusher has an unofficial Realtime Reddit API. You can read more about it on this blog post http://blog.pusher.com/pusher-realtime-reddit-api/.

But it basically you do nifty things like. It's also available in Ruby, Python, PHP, etc.

<!-- Include the Pusher JavaScript library -->
<script src="http://js.pusher.com/2.2/pusher.min.js"></script>

<script>
  // Open a Pusher connection to the Realtime Reddit API
  var pusher = new Pusher("50ed18dd967b455393ed");

  // Subscribe to the /r/AskReddit subreddit (lowercase)
  var subredditChannel = pusher.subscribe("askreddit");

  // Listen for new stories
  subredditChannel.bind("new-listing", function(listing) {
    // Output listing to the browser console
    console.log(listing);
  };
</script>

Disclaimer: I work for Pusher

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜