-
-
Notifications
You must be signed in to change notification settings - Fork 22
Authentication
To authenticate with Reddit, you are going to need as follows
- Reddit account username that has been authorized to your app (if you created your app, then you are one by default)
- Reddit account password
- Reddit App ID
- Reddit App Secret
Reddit4J client = Reddit4J.rateLimited().setUsername("Username").setPassword("Password")
.setClientId("App ID").setClientSecret("Secret")
.setUserAgent(new UserAgentBuilder().appname("App Name").author("Your Name").version("1.0"));
client.connect();Reddit will heavily restrict any generic User-Agent as they want to know what apps are doing what. Building a user agent from scratch however can be a little tedious, so we added a utility UserAgentBuilder. Here is an example of a user agent being built.
UserAgentBuilder userAgent = new UserAgentBuilder().appname("Reddit4J").author("masecla22").version("1.0");This is pretty easy to do and simply calling a list of methods on it will be able to do it
Reddit4J client = Reddit4J.rateLimited().setUsername("Username").setPassword("Password")
.setClientId("App ID").setClientSecret("Secret");Finally, you will need to set the user agent you built and obtain a token using the connect method.
UserAgentBuilder userAgent = new UserAgentBuilder().appname("Reddit4J").author("masecla22").version("1.0");
Reddit4J client = Reddit4J.rateLimited().setUsername("Username").setPassword("Password")
.setClientId("App ID").setClientSecret("Secret")
.setUserAgent(userAgent);
client.connect(); // Obtains a tokenReddit4J client = Reddit4J.rateLimited()
.setClientId("App ID").setClientSecret("Secret")
.setUserAgent(new UserAgentBuilder().appname("App Name").author("Your Name").version("1.0"));
client.userlessConnect();Reddit will heavily restrict any generic User-Agent as they want to know what apps are doing what. Building a user agent from scratch however can be a little tedious, so we added a utility UserAgentBuilder. Here is an example of a user agent being built.
UserAgentBuilder userAgent = new UserAgentBuilder().appname("Reddit4J").author("masecla22").version("1.0");This is pretty easy to do and simply calling a list of methods on it will be able to do it
Reddit4J client = Reddit4J.rateLimited().setClientId("App ID").setClientSecret("Secret");Finally, you will need to set the user agent you built and obtain a token using the connect method.
UserAgentBuilder userAgent = new UserAgentBuilder().appname("Reddit4J").author("masecla22").version("1.0");
Reddit4J client = Reddit4J.rateLimited().setClientId("App ID").setClientSecret("Secret")
.setUserAgent(userAgent);
client.userlessConnect(); // Obtains a tokenSomething wrong? Open an issue. Something missing? Open a pull request.