从 Reddit 子版块获取 JSON 格式的新帖子

发布于 2024-11-10 17:44:43 字数 556 浏览 9 评论 0原文

我该如何获取 JSON 格式的 Reddit 子版块的帖子?只需将 .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=new 时,到 new?sort=rising

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

How would I go about 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苹果你个爱泡泡 2024-11-17 17:44:43

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

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

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
牛↙奶布丁 2024-11-17 17:44:43

如果您有兴趣获取所有 Reddit 新帖子的实时流,Pusher 有一个非官方的实时 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 工作

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文