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;
}
}
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());
}
}
});
}
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);
}
Aggregations