Skip to content
thatJavaNerd edited this page Nov 12, 2014 · 24 revisions

To do anything of value with JRAW, you will have to obtain an instance of the RedditClient class:

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

Basic site features such as voting and commenting are provided by AccountManager

LoggedInAccount account = reddit.login(Credentials.standard("Unidan", "jackdaw12"));
AccountManager manager = new AccountManager(reddit);

manager.submitContent(...)
manager.reply(...)
manager.vote(...)

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 = // ...
manager.submitContent(new AccountManager.SubmissionBuilder(url, SUBREDDIT, TITLE));

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

// Do stuff with a submission
Submission submission = reddit.getSubmission("28d6vv"); // http://redd.it/28d6vv
manager.vote(submission, VoteDirection.UPVOTE);
manager.setSaved(submission, true);
manager.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