本文整理汇总了Java中net.dean.jraw.http.oauth.OAuthException类的典型用法代码示例。如果您正苦于以下问题:Java OAuthException类的具体用法?Java OAuthException怎么用?Java OAuthException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OAuthException类属于net.dean.jraw.http.oauth包,在下文中一共展示了OAuthException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
@Override
public void run() {
Credentials creds = Credentials.userless(
reddigramBot.config().clientId(),
reddigramBot.config().clientSecret(),
reddigramBot.deviceId()
);
OAuthData data;
try {
data = reddigramBot.client().getOAuthHelper().easyAuth(creds);
} catch (OAuthException ex) {
// Oh no! Complain to owner and shut down
reddigramBot.log("Couldn't authenticate the bot! Shutting down...");
ex.printStackTrace();
reddigramBot.sendToOwner("Couldn't complete OAuth with Reddit (message=" + ex.getMessage() + ")");
return;
}
reddigramBot.client().authenticate(data);
}
示例2: scanReddit
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
public ArrayList<String> scanReddit(AuthHelper helper, ArrayList<String> links) throws NetworkException, OAuthException {
RedditClient redditClient = helper.getRedditClient();
SubredditPaginator doto = new SubredditPaginator(redditClient,"dota2");
doto.setLimit(100);
doto.setTimePeriod(TimePeriod.ALL);
doto.setSorting(Sorting.NEW);
Listing<Submission> submissions = doto.next();
String linkUrl = null;
System.out.println("OK2");
for(Submission s : submissions){
linkUrl = s.getUrl();
System.out.println(linkUrl);
if(linkUrl.contains("oddshot") && !links.contains(linkUrl)){
Scanner.submissionList.add(s);
links.add(linkUrl);
}
}
return links;
}
示例3: onPastaCommand
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
@Command(aliases = {"pasta", "copypasta"}, description = "Gets a random copypasta from /r/copypasta.", usage = "pasta")
public static String onPastaCommand(String[] args, IMessage message) throws OAuthException, RateLimitException, DiscordException, MissingPermissionsException {
Listing<Submission> copypasta = null;
RedditClient redditClient;
try {
redditClient = Reddit.getRedditClient();
if (!redditClient.isAuthenticated()) {
Reddit.authReddit();
}
FluentRedditClient fluent = new FluentRedditClient(redditClient);
copypasta = fluent.subreddit("copypasta").fetch();
} catch (NetworkException | NullPointerException e) {
Reddit.authReddit();
onPastaCommand(args, message);
}
System.out.println("Serving some pasta.");
Random random = new Random();
if (copypasta != null) {
Submission pasta = copypasta.get(random.nextInt(copypasta.size()));
if (args.length > 0) {
message.delete();
return "Too many arguments! Use `~help` to get usages.";
} else if (args.length == 0) {
message.delete();
return StringUtils.abbreviate((":spaghetti: " + "**" + pasta.getTitle() + "**\n" + pasta.getSelftext()), 2000);
}
}
// Something went wrong, display error message
message.delete();
return "An error occurred, please try again later.";
}
示例4: onJokeCommand
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
@Command(aliases = {"joke", "prank"}, description = "Gets a random joke from /r/jokes.", usage = "joke")
public static String onJokeCommand(String[] args, IMessage message) throws OAuthException, RateLimitException, DiscordException, MissingPermissionsException {
Listing<Submission> jokes = null;
RedditClient redditClient;
try {
redditClient = Reddit.getRedditClient();
if (!redditClient.isAuthenticated()) {
Reddit.authReddit();
}
FluentRedditClient fluent = new FluentRedditClient(redditClient);
jokes = fluent.subreddit("jokes").fetch();
} catch (NetworkException | NullPointerException e) {
Reddit.authReddit();
onJokeCommand(args, message);
}
Random random = new Random();
System.out.println("Telling a bad joke.");
if (jokes != null) {
Submission joke = jokes.get(random.nextInt(jokes.size()));
if (args.length > 0) {
message.delete();
return "Too many arguments! Use `~help` to get usages.";
} else if (args.length == 0) {
message.delete();
return StringUtils.abbreviate((":rofl: " + "**" + joke.getTitle() + "**\n" + joke.getSelftext()), 2000);
}
}
// Something went wrong, display error message.
message.delete();
return "An error occurred, please try again";
}
示例5: main
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
public static void main(String[] args) throws OAuthException {
IDiscordClient client = Discord.createClient(Keys.DiscordBotToken, true);
EventDispatcher dispatcher = client.getDispatcher(); // Gets the EventDispatcher instance for this client instance
dispatcher.registerListener(new InterfaceListener()); // Registers the IListener example class from above
CommandHandler handler = new Discord4JHandler(client);
handler.setDefaultPrefix("~");
handler.registerCommand(new PastaCommand());
handler.registerCommand(new JokeCommand());
handler.registerCommand(new KahootCommand());
handler.registerCommand(new HelpCommand(handler));
}
示例6: ScraperBot
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
public ScraperBot() throws OAuthException {
UserAgent agent = UserAgent.of("script", "io.github.<username>", "v0.1", "<username>");
client = new RedditClient(agent);
Credentials cred = Credentials.script("<username>", "<password>", "<public key>", "<private key>");
OAuthData data = client.getOAuthHelper().easyAuth(cred);
client.authenticate(data);
posts = new HashMap<>();
}
示例7: main
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
public static void main(String[] args) {
try {
ScraperBot sb = new ScraperBot();
sb.getPosts(sb.getHeadlines(100));
SimpleMarkdown sm = new SimpleMarkdown();
sm.saveData(posts);
//TODO: scanner for searching
} catch (OAuthException | IOException e) {
e.printStackTrace();
}
}
示例8: handleOAuthSuccess
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
@Background
protected void handleOAuthSuccess(String url) {
try {
OAuthData resp = this.helper.onUserChallenge(url, this.credentials);
this.manager.getClient().authenticate(resp);
this.handleSuccess();
} catch (OAuthException ex) {
this.handleError(ex.getMessage());
}
}
示例9: init
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
public void init() {
log.info("got here");
try {
UserAgent myUserAgent = UserAgent.of("desktop", "com.flowchat", "v0.1", "dessalines");
redditClient = new RedditClient(myUserAgent);
Credentials credentials = Credentials.script(DataSources.PROPERTIES.getProperty("reddit_username"),
DataSources.PROPERTIES.getProperty("reddit_password"),
DataSources.PROPERTIES.getProperty("reddit_client_id"),
DataSources.PROPERTIES.getProperty("reddit_client_secret"));
OAuthData authData = redditClient.getOAuthHelper().easyAuth(credentials);
redditClient.authenticate(authData);
} catch (OAuthException e) {
e.printStackTrace();
}
}
示例10: authenticateUrl
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
/**
* Gets the deferred observable used for authenticating using the given url.
*
* @param url the url to authenticate with
* @return the deferred observable used for authenticating the given url
*/
public Observable<String> authenticateUrl(String url) {
return Observable.defer(() -> {
try {
return Observable.just(mJrawHelper.authenticateUrl(url));
} catch (OAuthException e) {
return Observable.error(e);
}
});
}
示例11: authenticateToken
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
/**
* Gets the deferred observable used for authenticating using the given
* refresh token.
*
* @param refreshToken the refresh toke to authenticate with
* @return the deferred observable used for authenticating the given
* refresh token
*/
public Observable<Boolean> authenticateToken(String refreshToken) {
return Observable.defer(() -> {
try {
return Observable.just(mJrawHelper.authenticateToken(refreshToken));
} catch (OAuthException e) {
return Observable.error(e);
}
});
}
示例12: authenticate
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
public AuthHelper authenticate() throws NetworkException, OAuthException{
AuthHelper helper = new AuthHelper();
UserAgent myUserAgent = UserAgent.of("desktop", "YouTubeBot", "0.1", "-YouTubeBot-");
RedditClient redditClient = new RedditClient(myUserAgent);
Credentials credentials = Credentials.script("-YouTubeBot-", "Ash3win#", "WnBQphrJ2jWY5A", "bJmaYXBDHUNfPGRpSEUPHOtLrIk");
OAuthData authData = redditClient.getOAuthHelper().easyAuth(credentials);
redditClient.authenticate(authData);
helper.setCredentials(credentials);
helper.setRedditClient(redditClient);
return(helper);
}
示例13: authReddit
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
public static RedditClient authReddit() throws OAuthException {
System.out.println("Reauthenticating Reddit");
Credentials credentials = Credentials.script("DiscordPastaBot", Keys.RedditPass, Keys.RedditID, Keys.RedditSecret);
redditClient.authenticate(redditClient.getOAuthHelper().easyAuth(credentials));
return redditClient;
}
示例14: authenticate
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
private static OAuthData authenticate() throws NetworkException, OAuthException {
return redditClient.getOAuthHelper().easyAuth(credentials);
}
示例15: authenticateToken
import net.dean.jraw.http.oauth.OAuthException; //导入依赖的package包/类
/**
* Authenticates the client using the given refresh token.
*
* @param refreshToken the refresh token to use
* @return true if the authentication was successful
* @throws OAuthException if there was a problem authenticating
*/
public boolean authenticateToken(String refreshToken) throws OAuthException {
mOAuthHelper.setRefreshToken(refreshToken);
OAuthData oAuthData = mOAuthHelper.refreshToken(mCredentials);
mRedditClient.authenticate(oAuthData);
return true;
}