use of twitter4j.auth.AccessToken in project ORCID-Source by ORCID.
the class OrcidSocialManagerImpl method tweet.
/**
* Tweet a message to the specified profile
*
* @param entity
* An entity containing the user information and the twitter
* credentials
* @return true if it was able to tweet the updates
* */
@SuppressWarnings("unchecked")
private boolean tweet(OrcidSocialEntity entity) {
String jsonCredentials = decrypt(entity.getEncryptedCredentials());
Map<String, String> credentials = (HashMap<String, String>) JSON.parse(jsonCredentials);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(twitterKey, twitterSecret);
AccessToken accessToken = new AccessToken(credentials.get(TWITTER_USER_KEY), credentials.get(TWITTER_USER_SECRET));
twitter.setOAuthAccessToken(accessToken);
try {
twitter.updateStatus(buildUpdateMessage(entity.getId().getOrcid()));
} catch (Exception e) {
LOGGER.error("Unable to tweet on profile {}", entity.getId().getOrcid());
return false;
}
return true;
}
use of twitter4j.auth.AccessToken in project ORCID-Source by ORCID.
the class OrcidSocialManagerImpl method enableTwitter.
/**
* Enables twitter on the user profile
*
* @param orcid
* @param pin
* oauth_verifier parameter that comes from twitter request
* */
@Override
public void enableTwitter(String userOrcid, String pin) throws Exception {
AccessToken accessToken = getOAuthAccessToken(userOrcid, pin);
String credentials = generateEncryptedTwitterCredentials(accessToken.getToken(), accessToken.getTokenSecret());
orcidSocialDao.save(userOrcid, OrcidSocialType.TWITTER, credentials);
}
Aggregations