Search in sources :

Example 1 with StudyTwitterPluginConfigurator

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());
            }
        }
    });
}
Also used : RequestToken(twitter4j.auth.RequestToken) AccessToken(twitter4j.auth.AccessToken) IOException(java.io.IOException) StudyTwitterPluginConfigurator(com.jetbrains.edu.learning.StudyTwitterPluginConfigurator) TwitterException(twitter4j.TwitterException)

Aggregations

StudyTwitterPluginConfigurator (com.jetbrains.edu.learning.StudyTwitterPluginConfigurator)1 IOException (java.io.IOException)1 TwitterException (twitter4j.TwitterException)1 AccessToken (twitter4j.auth.AccessToken)1 RequestToken (twitter4j.auth.RequestToken)1