Search code examples
javascriptjsonnode.jsnode-webkitreddit

Reddit Api Error trying to get reddit self text via snoocore node.js


I'm tryng to get the self.text on a post and using this route:

reddit('/r/Denmark/comments/2jc5yk/how_to_live_in_denmark.json').listing({ 
        context: 1,
        limit: 10,
        sort: 'hot',
    })
    .then(function(result) { 
        console.log(result);
    });

I have also tried using .get(), without .json and without /how_to_live_in_denmark but still the same error.

When I input the route in my browser, I get the desired JSON.

The error i get:

Uncaught Error: Invalid path provided! This endpoint does not exist. Make sure that your call matches the routes that are defined in Reddit's API documentation

What am i doing wrong?


Solution

  • Update: 2015-02-09

    Snoocore now accepts URLS's with embedded values and does not require placeholders if you do not wish to use them.


    I'm the creator of this API wrapper. I'll have to monitor StackOverflow a little bit more to catch these quicker. Feel free to open new issues on GitHub as well when you get stuck on something for a quicker response!

    It looks like you are trying to call this endpoint:

    GET /r/[subreddit]/comments/article

    Basically anything that is in brackets is optional in Snoocore, and anything in italics is an URL parameter that you will need to define placeholders for in the call (using $parameter). More information on this can be read in the documentation (feel free to ask questions or improve upon the documentation if it isn't clear!)

    So in your case, you will want to do this:

    reddit('/r/$subreddit/comments/$article').get({
      $subreddit: 'Denmark',
      $article: '2jc5yk',
      context: 1,
      limit: 10,
      sort: 'hot'
    }).done(function(result) {
      console.log(result);
    });
    

    Note that instead of defining the url parameters in the call, the are now referenced by $subreddit and $article respectivly.

    Note that comments are not a listing, and therefore can't use the listings interface as you tried to do in your question.