コード例 #1
0
 /**
  * Create new social connection
  *
  * @param provider {@link SocialProvider}
  * @param accessGrant {@link AccessGrant}
  * @param socialAccountId social account id.
  * @param userAccount {@link UserAccount}
  * @param providerProfileUrl provider profile url.
  * @return
  */
 public SocialAccount updateSocialAccountConnection(
     final AccessGrant accessGrant, // OAuth2
     final String socialAccountId,
     final SocialAccount currentSocialAccount) {
   log.debug("Add Connection " + accessGrant);
   log.debug("Add Connection " + socialAccountId);
   // reference to social account.
   // connection.setSocialAccount(socialAccount);
   // store oauth provider permissions.
   if (SocialProvider.getTypeAuth(currentSocialAccount.getAccounType()).equals(TypeAuth.OAUTH1)) {
     // OAuth access token.
     // connection.setAccessToken(token.getValue());
     // OAuth1
     // connection.setSecretToken(token.getSecret());
     // TODO: pending OAUTH1.
     log.debug("pending OAUTH1 - OAuth 1 social connection is not available right now.");
   } else if (SocialProvider.getTypeAuth(currentSocialAccount.getAccounType())
       .equals(TypeAuth.OAUTH2)) {
     // OAuth2
     currentSocialAccount.setAccessToken(accessGrant.getAccessToken());
     currentSocialAccount.setRefreshToken(accessGrant.getRefreshToken());
     currentSocialAccount.setExpires(accessGrant.getExpires());
   }
   Assert.assertNotNull(socialAccountId);
   currentSocialAccount.setSocialProfileId(socialAccountId);
   this.saveOrUpdate(currentSocialAccount); // TODO: this seems not save or update properly.
   log.debug("Added Connection:{" + currentSocialAccount.toString());
   return currentSocialAccount;
 }
コード例 #2
0
 /**
  * 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;
 }