【问题标题】:Getting NEW posts from a subreddit in JSON从 JSON 中的 subreddit 获取新帖子
【发布时间】:2011-09-05 05:08:50
【问题描述】:

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

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

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

而 /new?sort=new.json 当然行不通。

【问题讨论】:

  • 我们如何在android中使用reddit api获取订阅subreddits列表?
  • 如何在android中调用这个链接reddit.com/subreddits/mine

标签: api reddit


【解决方案1】:

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

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

【讨论】:

  • 我在哪里可以找到 Reddit 的所有可用 json 修饰符的列表?
  • @NeilWilliams 请问你在哪里看到的?虽然它有效,但据我所知,文档说所有调用都需要 OAuth,而我在任何地方都没有看到这种特殊用法的记录?
  • 我们现在肯定会推荐并更喜欢您使用 OAuth。不过,上述 URL 结构在 OAuth 上没有什么不同。
  • 你也可以加&limit=100来获取更多的帖子,但这就是限制
  • @1j01 +1 for "the limit of the limit"
【解决方案2】:

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

【讨论】:

  • 显然我正在尝试这个(来自 Pusher 博客),我可以看到它正在执行 subredditChannel.bind('pusher:subscription_succeeded', function(data) { console.log("Subscribed"); } );但在那之后,“subredditChannel.bind("new-listing",callback)" 没有返回。为什么这样 ?你能帮我解决这个问题吗?
  • 如何获取用户订阅的 subreddits/mysubreddits 列表?
  • 这似乎不再起作用了。修复代码中的语法错误后,我没有看到任何错误,而且我看到它正在执行看起来像是长轮询的操作。然而,所有的民意调查都以 204 无内容返回,而各种新帖子被提交给 askreddit。 console.log(listing) 永远不会被触发。
  • 是的。好像这个公共频道现在已经关闭了。您必须创建自己的后端才能使其正常工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-27
  • 2018-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多