Reddit API returns only one post

I am trying to get all the links in subreddit using the API, but it returns only one url. Here is the code I have:

var request = require('request'); webpage = 'http://www.reddit.com/r/AmazonUnder5/top.json?limit=100'; //login request.post('http://www.reddit.com/api/login',{form:{api_type:'json', passwd:'password', rem:true, user:'username'}}); //get urls request({uri : webpage, json:true, headers:{useragent: 'mybot v. 0.0.1'}}, function(error, response, body) { if(!error && response.statusCode == 200) { for(var key in body.data.children) { var url = body.data.children[key].data.url; console.log(url); } } }); 

When I visit the json link in my browser, it returns all 100 messages.

+4
source share
1 answer

This is because only 1 exists at the top

http://www.reddit.com/r/AmazonUnder5/top

You can use hot instead

http://www.reddit.com/r/AmazonUnder5/hot.json

In addition, you do not need to register to make public requests for receiving

Edit: you get so few results because you are not logged in correctly

When logging in, use

 "op" => "login" 

Parameter and check which cookies and data will be returned.

I also recommend using the ssl login url as this works for me

 https://ssl.reddit.com/api/login/ 
+2
source

Source: https://habr.com/ru/post/1493835/


All Articles