从JSON中的subreddit获取新帖子

Chr*_*ngs 21 api reddit

我如何在JSON中获取subreddit 的帖子?只需将.json添加到url(http://www.reddit.com/r/SOME_SUBREDDIT/new.json)即可返回以下内容:

{
    kind: "Listing"
    -
    data: {
        modhash: ""
        children: [ ]
        after: null
        before: null
    }
}
Run Code Online (Sandbox Code Playgroud)

children数组不包含任何帖子.我发现http://www.reddit.com/r/SOME_SUBREDDIT/new实际上路由到new?sort = rising当我需要的是new?sort = new.

和/ new?sort = new.json当然不会工作.

Nei*_*ams 56

.json修改应在路径组件,而不是整个URL的结尾放.您要查找的网址是:

http://www.reddit.com/r/subreddit/new.json?sort=new
Run Code Online (Sandbox Code Playgroud)

  • 有关API的@NamitSinha文档,请访问https://www.reddit.com/dev/api (4认同)
  • 我在哪里寻找Reddit所有可用的json修饰符的列表? (2认同)
  • 您还可以添加"&limit = 100"以获得更多帖子,但这是限制的限制 (2认同)

Syl*_*Syl 7

如果您有兴趣获得所有Reddit新帖子的实时流,Pusher有一个非官方的Realtime Reddit API.您可以在此博客文章http://blog.pusher.com/pusher-realtime-reddit-api/上阅读更多相关信息.

但它基本上你做了很好的事情.它也可以在Ruby,Python,PHP等中使用.

<!-- 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>
Run Code Online (Sandbox Code Playgroud)

免责声明:我为Pusher工作