Search in sources :

Example 6 with RequestToken

use of twitter4j.auth.RequestToken in project ORCID-Source by ORCID.

the class OrcidSocialManagerImpl method getTwitterRequestToken.

/**
     * Get the twitter RequestToken
     * 
     * @return The twitter RequestToken
     * */
private RequestToken getTwitterRequestToken(String orcid) throws Exception {
    // If it exists, use it once and discard it
    if (requestTokenMap.containsKey(orcid)) {
        RequestToken result = requestTokenMap.get(orcid);
        requestTokenMap.remove(orcid);
        return result;
    } else {
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(twitterKey, twitterSecret);
        RequestToken requestToken = twitter.getOAuthRequestToken();
        requestTokenMap.put(orcid, requestToken);
        return requestToken;
    }
}
Also used : RequestToken(twitter4j.auth.RequestToken) Twitter(twitter4j.Twitter) TwitterFactory(twitter4j.TwitterFactory)

Example 7 with RequestToken

use of twitter4j.auth.RequestToken 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)

Example 8 with RequestToken

use of twitter4j.auth.RequestToken in project ORCID-Source by ORCID.

the class OrcidSocialManagerImpl method getOAuthAccessToken.

/**
     * Get the twitter AccessToken
     * 
     * @return The twitter AccessToken
     * */
private AccessToken getOAuthAccessToken(String orcid, String pin) throws Exception {
    RequestToken requestToken = getTwitterRequestToken(orcid);
    Twitter twitter = new TwitterFactory().getInstance();
    twitter.setOAuthConsumer(twitterKey, twitterSecret);
    return twitter.getOAuthAccessToken(requestToken, pin);
}
Also used : RequestToken(twitter4j.auth.RequestToken) Twitter(twitter4j.Twitter) TwitterFactory(twitter4j.TwitterFactory)

Aggregations

RequestToken (twitter4j.auth.RequestToken)8 Twitter (twitter4j.Twitter)4 TwitterFactory (twitter4j.TwitterFactory)4 AccessToken (twitter4j.auth.AccessToken)4 IOException (java.io.IOException)3 TwitterException (twitter4j.TwitterException)3 Properties (java.util.Properties)2 StudyTwitterPluginConfigurator (com.jetbrains.edu.learning.StudyTwitterPluginConfigurator)1 HttpServletRouter (h2weibo.HttpServletRouter)1 DBHelper (h2weibo.model.DBHelper)1 T2WUser (h2weibo.model.T2WUser)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HttpSession (javax.servlet.http.HttpSession)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1 twitter4j (twitter4j)1