diff options
Diffstat (limited to 'juick-server/src/main/java/com/juick')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/TopManager.java | 4 | ||||
-rw-r--r-- | juick-server/src/main/java/com/juick/server/TwitterManager.java (renamed from juick-server/src/main/java/com/juick/server/CrosspostManager.java) | 25 |
2 files changed, 19 insertions, 10 deletions
diff --git a/juick-server/src/main/java/com/juick/server/TopManager.java b/juick-server/src/main/java/com/juick/server/TopManager.java index 918e5ace..4d080f54 100644 --- a/juick-server/src/main/java/com/juick/server/TopManager.java +++ b/juick-server/src/main/java/com/juick/server/TopManager.java @@ -45,7 +45,7 @@ public class TopManager { @Inject private FacebookPageManager facebookPageManager; @Inject - private CrosspostManager crosspostManager; + private TwitterManager twitterManager; @Inject private UserService userService; @@ -77,7 +77,7 @@ public class TopManager { logger.warn("facebook error {}: {}", statusCode.value(), responseString); } jmsg.setUser(serviceUser); - crosspostManager.twitterPost(jmsg); + twitterManager.twitterPost(jmsg); } }); } diff --git a/juick-server/src/main/java/com/juick/server/CrosspostManager.java b/juick-server/src/main/java/com/juick/server/TwitterManager.java index bfd5af30..8e000b07 100644 --- a/juick-server/src/main/java/com/juick/server/CrosspostManager.java +++ b/juick-server/src/main/java/com/juick/server/TwitterManager.java @@ -26,9 +26,9 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; -import org.springframework.social.twitter.api.Twitter; -import org.springframework.social.twitter.api.impl.TwitterTemplate; import org.springframework.stereotype.Component; +import twitter4j.TwitterFactory; +import twitter4j.conf.ConfigurationBuilder; import javax.annotation.Nonnull; import javax.inject.Inject; @@ -37,11 +37,9 @@ import javax.inject.Inject; * @author Ugnich Anton */ @Component -public class CrosspostManager { - private final static String FBURL = "https://graph.facebook.com/me/feed"; - private final static String VKURL = "https://api.vk.com/method/wall.post"; +public class TwitterManager { - private static Logger logger = LoggerFactory.getLogger(CrosspostManager.class); + private static Logger logger = LoggerFactory.getLogger(TwitterManager.class); @Inject private CrosspostService crosspostService; @@ -51,6 +49,15 @@ public class CrosspostManager { @Value("${twitter_consumer_secret:secret}") private String twitter_consumer_secret; + private final ConfigurationBuilder configurationBuilder; + + public TwitterManager() { + configurationBuilder = new ConfigurationBuilder() + .setDebugEnabled(true) + .setOAuthConsumerKey(twitter_consumer_key) + .setOAuthConsumerSecret(twitter_consumer_secret); + } + @Async @EventListener public void onApplicationEvent(@Nonnull MessageEvent event) { @@ -71,9 +78,11 @@ public class CrosspostManager { status = status.substring(0, 254) + "…"; } status += " http://juick.com/" + jmsg.getMid(); - Twitter twitter = new TwitterTemplate(twitter_consumer_key, twitter_consumer_secret, t.getToken(), t.getSecret()); + TwitterFactory tf = new TwitterFactory(configurationBuilder + .setOAuthAccessToken(t.getToken()) + .setOAuthAccessTokenSecret(t.getSecret()).build()); try { - twitter.timelineOperations().updateStatus(status); + tf.getInstance().updateStatus(status); } catch (Exception e) { logger.info("Twitter exception", e); } |