Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submission.getComments() always returns null #29

Closed
Ninhydrinal opened this issue Dec 19, 2014 · 4 comments
Closed

Submission.getComments() always returns null #29

Ninhydrinal opened this issue Dec 19, 2014 · 4 comments

Comments

@Ninhydrinal
Copy link

Even when I know that the submission has comments and getCommentCount() tells me the right amount of comments, getComments() always returns null.

@mattbdean
Copy link
Owner

Can you include the code that is producing this error?

@Ninhydrinal
Copy link
Author

I already deleted everything I had wrote before so here's something I just quickly threw together.

public static void main(String[] args) {
    RedditClient reddit = new RedditClient("USER-AGENT");
    try {
        LoggedInAccount account = reddit.login(Credentials.standard("****", "****"));
    } catch (NetworkException e) {
        e.printStackTrace();
    } catch (ApiException e) {
        e.printStackTrace();
    }
    AccountManager manager = new AccountManager(reddit);
    SubredditPaginator subreddit = Paginators.subreddit(reddit, "funny");
    subreddit.setLimit(10);
    subreddit.setTimePeriod(TimePeriod.DAY);
    subreddit.setSorting(Sorting.TOP);
    Listing<Submission> submissions = subreddit.next();
    for (Submission s : submissions){
        Listing<Comment> comments = s.getComments();
        System.out.println(s.getTitle());
        if (comments == null){
            System.out.println("Comments = null");
        }
        System.out.println(s.getCommentCount());
    }
}

Output:

We have been putting this little Chewbacca in the X-mas tree for ages and I never really knew why... I just found out my mom thinks he is a gingerbread man.
Comments = null
322
For Megan
Comments = null
580
My co-worker's friend just saw this in Florida while driving..they were even barking.
Comments = null
611
My wife wanted jewelry for Christmas....don't think she'll be too happy
Comments = null
887
My rejected pitch for our office Christmas cards.
Comments = null
222
Trying to teach my girlfriend how the thermostat works.
Comments = null
908
A movie that North Korea is okay with
Comments = null
105
So I decided to try something I saw in this subreddit...
Comments = null
434
This Dark Souls 2 Review
Comments = null
357
Punked kim jong un
Comments = null
408

@mattbdean
Copy link
Owner

Reddit doesn't include comments in responses to general pagination, like through a subreddit. Only when that submission is queried directly does Reddit give you that post's comments.

An example:

public static void main(String[] args) throws NetworkException {
    RedditClient reddit = new RedditClient("USER-AGENT");
    SubredditPaginator subreddit = Paginators.subreddit(reddit, "funny");

    for (Submission s : subreddit.next()) {
        Submission fullSubmissionData = reddit.getSubmission(s.getId());
        System.out.println(fullSubmissionData.getTitle());
        System.out.println(fullSubmissionData.getComments());
    }
}

@Ninhydrinal
Copy link
Author

Oh, that makes sense. Thanks, sorry for the bother.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants