如何使用 jraw 生成 Reddit 保存的项目列表?

How can I generate a list of Reddit saved items using jraw?

我正在尝试使用 JRAW 生成我所有已保存的 reddit 项目的列表。

我已经完成了 Quickstart , and successfully managed to login and retrieve information, and I can get a list of items on the Frontpage from the Cookbook,但我不知道如何获得我保存的项目列表(评论和帖子)或我自己的帖子列表(还有评论和帖子)。

保存的项目位于 https://www.reddit.com/user/<username>/saved/,但我不知道如何让 jraw 检索和解析它,或者如果 api 使用不同的 URL。

编辑:我想我可能需要使用 UserContributionPaginator,但我还没有完全弄清楚如何让它工作。

解决了。

package com.jraw;

import net.dean.jraw.RedditClient;
import net.dean.jraw.http.UserAgent;
import net.dean.jraw.http.oauth.Credentials;
import net.dean.jraw.http.oauth.OAuthData;
import net.dean.jraw.http.oauth.OAuthException;
import net.dean.jraw.models.Contribution;
import net.dean.jraw.models.Listing;
import net.dean.jraw.paginators.UserContributionPaginator;

public class printSaved {

    public static void main(String [] args) {
        UserAgent myUserAgent = UserAgent.of("desktop", "com.jraw.printSaved", "v0.01", "user");
        RedditClient redditClient = new RedditClient(myUserAgent);
        String username = "username";
        Credentials credentials = Credentials.script(username, "<password>", "<clientId>", "<clientSecret>");

        OAuthData authData = null;
        try {
            authData = redditClient.getOAuthHelper().easyAuth(credentials);
        } catch (OAuthException e) {
            e.printStackTrace();
        }
        redditClient.authenticate(authData);

        UserContributionPaginator saved = new UserContributionPaginator(redditClient,"saved",username);

        Listing<Contribution> savedList = saved.next();

        for (Contribution item : savedList) {
            System.out.println(item);
        }
    }
}