/** * Get Access Token. * * @param accountId * @param provider * @return * @throws EnMeNoResultsFoundException */ public OAuth1Token getAccessToken(String accountId, SocialProvider provider) throws EnMeNoResultsFoundException { final SocialAccount ac = this.getAccountConnection(accountId, provider); if (ac != null) { final OAuth1Token oAuthToken = new OAuth1Token(ac.getAccessToken(), ac.getSecretToken()); return oAuthToken; } else { throw new EnMeNoResultsFoundException("connection not found"); } }
/** * Public Tweet Poll (OAuth method). * * @param tweetText tweet text * @return status of tweet * @throws EnMeExpcetion exception */ public TweetPublishedMetadata publicTweetPoll( final String tweetText, final SocialAccount socialAccount, final Set<HashTag> hashtags) throws EnMeExpcetion { TweetPublishedMetadata published = new TweetPublishedMetadata(); log.debug("publicTweetPoll:{ " + tweetText); if (socialAccount.getAccounType().equals(SocialProvider.TWITTER)) { log.debug("Publish on TWITTER"); final TwitterAPIOperations twitterAPIOperations = new TwitterAPITemplate( EnMePlaceHolderConfigurer.getProperty("twitter.oauth.consumerSecret"), EnMePlaceHolderConfigurer.getProperty("twitter.oauth.consumerKey"), socialAccount); try { published = twitterAPIOperations.updateStatus(tweetText); } catch (Exception e) { log.error(e); e.printStackTrace(); } } else if (socialAccount.getAccounType().equals(SocialProvider.IDENTICA)) { log.debug("Publish on IDENTICA"); final IdenticaAPIOperations identicaAPIOperations = new IdenticaAPITemplate( EnMePlaceHolderConfigurer.getProperty("identica.consumer.key"), EnMePlaceHolderConfigurer.getProperty("identica.consumer.secret"), socialAccount.getAccessToken(), socialAccount.getSecretToken()); try { log.debug("Publish on Identica............>"); published = identicaAPIOperations.updateStatus(tweetText); log.debug("Publish on Identica...... " + published); } catch (Exception e) { published.setDatePublished(Calendar.getInstance().getTime()); log.error(e); e.printStackTrace(); } } else if (socialAccount.getAccounType().equals(SocialProvider.PLURK)) { log.debug("Publish on PLURK"); final PlurkAPIOperations tumblrAPIOperations = new PlurkAPITemplate( EnMePlaceHolderConfigurer.getProperty("plurk.consumer.key"), EnMePlaceHolderConfigurer.getProperty("plurk.consumer.secret"), socialAccount.getAccessToken(), socialAccount.getSecretToken()); try { log.debug("Publish on Identica............>"); published = tumblrAPIOperations.updateStatus(tweetText); log.debug("Publish on Identica...... " + published); } catch (Exception e) { published.setDatePublished(Calendar.getInstance().getTime()); log.error(e); e.printStackTrace(); } } else if (socialAccount.getAccounType().equals(SocialProvider.TUMBLR)) { log.debug("Publish on TUMBLR"); final TumblrAPIOperations tumblrAPIOperations = new TumblrAPITemplate( EnMePlaceHolderConfigurer.getProperty("tumblr.consumer.key"), EnMePlaceHolderConfigurer.getProperty("tumblr.consumer.secret"), socialAccount.getAccessToken(), socialAccount.getSecretToken()); try { log.debug("Publish on TUMBLR............>"); published = tumblrAPIOperations.updateStatus(tweetText, socialAccount, hashtags); log.debug("Publish on TUMBLR...... " + published); } catch (Exception e) { published.setDatePublished(Calendar.getInstance().getTime()); log.error(e); e.printStackTrace(); } } else if (socialAccount.getAccounType().equals(SocialProvider.FACEBOOK)) { log.debug("Publish on FACEBOOK"); FacebookAPIOperations facebookAPIOperations = new FacebookAPITemplate(socialAccount.getAccessToken()); try { log.debug("Publish on FACEBOOK............>"); published = facebookAPIOperations.updateStatus(tweetText); log.debug("Publish on FACEBOOK...... " + published); published.setDatePublished(Calendar.getInstance().getTime()); } catch (HttpClientErrorException e) { log.error("-----------------------FACEBOOK EXPIRED TOKEN----------------------- 1"); log.error(e.getStatusCode()); log.error(e.getResponseBodyAsString()); log.error(e.getStatusText()); published.setDatePublished(Calendar.getInstance().getTime()); // refresh token point. // offline_access scope permission is enabled by default . In this case // https://developers.facebook.com/docs/authentication/permissions/ log.error("-----------------------FACEBOOK EXPIRED TOKEN----------------------- 2"); e.printStackTrace(); } catch (Exception e) { published.setDatePublished(Calendar.getInstance().getTime()); log.error(e); e.printStackTrace(); } } else if (socialAccount.getAccounType().equals(SocialProvider.LINKEDIN)) { log.debug("Publish on LinkedIn"); LinkedInAPIOperations linkedInAPIOperations = new LinkedInAPITemplate( EnMePlaceHolderConfigurer.getProperty("linkedIn.oauth.api.key"), EnMePlaceHolderConfigurer.getProperty("linkedIn.oauth.api.secret"), socialAccount.getAccessToken(), socialAccount.getSecretToken()); try { log.debug("Publish on LinkedIn 1............>"); published = linkedInAPIOperations.updateStatus(tweetText); published.setTextTweeted(tweetText); published.setDatePublished(Calendar.getInstance().getTime()); published.setTweetId(RandomStringUtils.randomAscii(15)); log.debug("Publish on LinkedIn 2...... " + published); } catch (Exception e) { published.setDatePublished(Calendar.getInstance().getTime()); log.error(e); e.printStackTrace(); } } else if (socialAccount.getAccounType().equals(SocialProvider.GOOGLE_BUZZ)) { BuzzAPIOperations buzzInAPIOperations = new GoogleBuzzAPITemplate(socialAccount); try { log.debug("Publish on LinkedIn............>"); published = buzzInAPIOperations.updateStatus(tweetText); published.setTextTweeted(tweetText); published.setDatePublished(Calendar.getInstance().getTime()); published.setTweetId(RandomStringUtils.randomAscii(15)); log.debug("Publish on LinkedIn...... " + published); } catch (Exception e) { published.setDatePublished(Calendar.getInstance().getTime()); log.error(e); e.printStackTrace(); } } if (published != null) { log.debug("publicTweetPoll:s " + published.toString()); } return published; }