use of com.jetbrains.edu.learning.StudyTwitterPluginConfigurator in project intellij-community by JetBrains.
the class StudyTwitterUtils method authorizeAndUpdateStatus.
/**
* Show twitter dialog, asking user to tweet about his achievements. Post tweet with provided by panel
* media and text.
* As a result of succeeded tweet twitter website is opened in default browser.
*/
public static void authorizeAndUpdateStatus(@NotNull final Project project, @NotNull final Twitter twitter, @NotNull final StudyTwitterUtils.TwitterDialogPanel panel) throws TwitterException {
RequestToken requestToken = twitter.getOAuthRequestToken();
BrowserUtil.browse(requestToken.getAuthorizationURL());
ApplicationManager.getApplication().invokeLater(() -> {
String pin = createAndShowPinDialog();
if (pin != null) {
try {
AccessToken token = twitter.getOAuthAccessToken(requestToken, pin);
StudyTwitterPluginConfigurator configurator = StudyUtils.getTwitterConfigurator(project);
if (configurator != null) {
configurator.storeTwitterTokens(project, token.getToken(), token.getTokenSecret());
updateStatus(panel, twitter);
} else {
LOG.warn("No twitter configurator is provided for the plugin");
}
} catch (TwitterException e) {
if (e.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
LOG.warn("Unable to get the access token.");
LOG.warn(e.getMessage());
}
} catch (IOException e) {
LOG.warn(e.getMessage());
}
}
});
}
Aggregations