-4

I am trying to achieve the following with Javascript:

Given a reddit username , I want to retrieve the maximum amount of comments allowed for this user.

So far what i have managed to do is retrieve only the 25 latest comments which is the default reddit behaviour. Typing in the browser for example the following url, we receive 25 comments in the json response.

"https://www.reddit.com/user/spez/.json"

We can limit or extend the number of comments from a user ( name of user is spez in the example) as follows:

"https://www.reddit.com/user/spez/.json?limit=1000"

However how could I also use limit with the following ?

$.getJSON(
       "http://www.reddit.com/u/"+ user + "/.json?jsonp=?",function foo(result) {
        $.each(result.data.children.slice(0, 10),
            function (i, post) {
              $("#reddit-content").append( '<br>' + post.data.body );
              $("#reddit-content").append( '<hr>' );
            });
        }
      )
2
  • 2
    append &limit=1000 ? Commented Jul 29, 2017 at 13:29
  • Thanks! this worked... Commented Jul 29, 2017 at 13:33

1 Answer 1

0

Like this:

$.getJSON(
       "http://www.reddit.com/u/"+ user + "/.json",{ limit: 1000 },function foo(result) {
        $.each(result.data.children.slice(0, 10),
            function (i, post) {
              $("#reddit-content").append( '<br>' + post.data.body );
              $("#reddit-content").append( '<hr>' );
            });
        }
      )

Here's the doc: http://api.jquery.com/jquery.getjson/

The signature of getJSON is url, data, success. In your call you sent in the url, and the success callback. But you can also send in data that's a plain object or a string. You can see I sent in an object { limit : 1000 }, jquery will parse that so the request will be

https://www.reddit.com/user/spez/.json?limit=1000

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.