An open API service indexing awesome lists of open source software.

https://github.com/palexdev/raw4j


https://github.com/palexdev/raw4j

Last synced: 6 months ago
JSON representation

Awesome Lists containing this project

README

          

RAW4J



RAW4J is a new Reddit API Wrapper for Java.
As of now it's still in development, see the [Wiki](https://github.com/palexdev/RAW4J/wiki) to check what has been implemented and what it's still lacking.

Example of usage

```java
/*
The main class is RedditClient. It offers method to login and to access Reddit APIs.
To obtain an instance of RedditClient you first need to build an OAuthParameters object. This contains
all the needed information to successfully authenticate your app and retrieve the access token.
Let's see an example for a Web App.
*/
OAuthParameters parameters = new OAuthParameters.AuthCodeFlowBuilder()
.setUserAgent(USER_AGENT)
.setClientID(APP_CLIENT_ID)
.setClientSecret(APP_CLIENT_SECRET)
.setRedirectURI(REDIRECT_URI)
.setPermanent(...) //(Optional, true or false, check OAuth Types in wiki for more info)
.setScopes(A List of scopes)
.build(LoginType.WEB_APP); // Note that for the Authorization Code Flow you must specify if it's a Web App or an Installed App

RedditClient client = RedditClient.login(parameters);

/*
Now that you have obtained the client instance, it's recommended to check if the instance is not null.
This can happen if some error occurred during the OAuth Flow (the user denied the access for example).
To make calls to Reddit APIs, for example to retrieve a user info...
*/
User user = client.api().userApi().getUser(USERNAME);

/*
Or to retrieve the logged user info...
*/
User user = client.api().accountApi().getLoggedUser();

/*
Note that the logged user info are stored in memory, so if you need to refresh the data
you must call...
*/
User user = client.api().userApi().refreshLoggedUser().getLoggedUser();
```