You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.2 KiB
Java
32 lines
1.2 KiB
Java
package sh.adb.RandomRedditMemesAPI;
|
|
|
|
import com.github.jreddit.oauth.RedditOAuthAgent;
|
|
import com.github.jreddit.oauth.RedditToken;
|
|
import com.github.jreddit.oauth.app.RedditApp;
|
|
import com.github.jreddit.oauth.app.RedditInstalledApp;
|
|
import com.github.jreddit.oauth.exception.RedditOAuthException;
|
|
import com.sun.net.httpserver.HttpServer;
|
|
import org.json.simple.parser.ParseException;
|
|
|
|
import java.io.IOException;
|
|
import java.net.InetSocketAddress;
|
|
|
|
public class Main {
|
|
public static void main(String[] args) throws IOException, RedditOAuthException, ParseException {
|
|
//start RedditAPI
|
|
RedditAPI redditClient = new RedditAPI();
|
|
System.out.println("RedditAPI started - the token is");
|
|
System.out.println(redditClient.token.getAccessToken());
|
|
//start httpServer
|
|
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
|
|
server.createContext("/", new FallbackHandler());
|
|
//server.createContext("/api/v1/", new StandardHandler());
|
|
server.createContext("/api/v1/r/", new CommunityHandler(redditClient));
|
|
server.setExecutor(null);
|
|
server.start();
|
|
System.out.println("server started");
|
|
}
|
|
}
|
|
|
|
|