Search in sources :

Example 21 with AccessToken

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;
}
Also used : HashMap(java.util.HashMap) AccessToken(twitter4j.auth.AccessToken) Twitter(twitter4j.Twitter) TwitterFactory(twitter4j.TwitterFactory)

Example 22 with AccessToken

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);
}
Also used : AccessToken(twitter4j.auth.AccessToken)

Aggregations

AccessToken (twitter4j.auth.AccessToken)22 IOException (java.io.IOException)8 TwitterException (twitter4j.TwitterException)7 Twitter (twitter4j.Twitter)5 TwitterFactory (twitter4j.TwitterFactory)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 InetSocketAddress (java.net.InetSocketAddress)4 Socket (java.net.Socket)4 GeneralSecurityException (java.security.GeneralSecurityException)4 Calendar (java.util.Calendar)4 SSLContext (javax.net.ssl.SSLContext)4 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)4 DefaultHttpClientConnection (org.apache.http.impl.DefaultHttpClientConnection)4 BasicHttpEntityEnclosingRequest (org.apache.http.message.BasicHttpEntityEnclosingRequest)4 BasicHttpParams (org.apache.http.params.BasicHttpParams)4 HttpParams (org.apache.http.params.HttpParams)4 RequestToken (twitter4j.auth.RequestToken)4 T2WUser (h2weibo.model.T2WUser)3 File (java.io.File)3 KeyManagementException (java.security.KeyManagementException)3