Skip to content
thatJavaNerd edited this page Oct 13, 2014 · 24 revisions

To do anything major with JRAW, you will have to use the RedditClient class:

RedditClient reddit = new RedditClient("MY-USER-AGENT");

If you want to anything that involves an authenticated user, you will have to login:

LoggedInAccount account = reddit.login("MY-USERNAME", "MY-PASSWORD");

Note: If you have enabled site-wide HTTPS, then RedditClient will send HTTPS requests by default. To change this, use reddit.setHttpsDefault(boolean).

##Examples Iterate through the front page

SubredditPaginator frontPage = new SubredditPaginator(reddit); // Second parameter could be a subreddit
while (frontPage.hasNext()) {
    Listing<Submission> submissions = frontPage.next();

    for (Submission submission : submissions) {
        System.out.println(submission.getTitle());
    }
}

See here for more information on Paginators.

Post a link

// Link
URL url = // ...
account.submitContent(new LoggedInAccount.SubmissionBuilder(url, SUBREDDIT, TITLE));

// Self-post
String content = // ...
account.submitContent(new LoggedInAccount.SubmissionBuilder(content, SUBREDDIT, TITLE));

// Do stuff with a submission
Submission submission = reddit.getSubmission("28d6vv"); // http://redd.it/28d6vv
me.vote(submission, VoteDirection.UPVOTE);
me.setSaved(submission, true);
me.setHidden(submission, true);

The best way to learn how to use a library is by looking at its unit tests. These tests cover most every part of the library.

Clone this wiki locally