25

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

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

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

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

4

2 回答 2

67

.json修饰符应该放在路径组件的末尾,而不是整个 URL 。您要查找的网址是:

http://www.reddit.com/r/subreddit/new.json?sort=new
于 2011-05-31T05:57:35.460 回答
8

如果你有兴趣获得所有 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>

免责声明:我为 Pusher 工作

于 2014-08-12T12:08:46.697 回答