如何在JSON中获取subreddit的新帖子?只需将.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 当然不会工作。
答案 0 :(得分:55)
.json
修饰符应放在路径组件的末尾,而不是整个URL。您要查找的网址是:
http://www.reddit.com/r/subreddit/new.json?sort=new
答案 1 :(得分: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>
免责声明:我为Pusher工作