Search in sources :

Example 1 with DirectMessage

use of org.springframework.social.twitter.api.DirectMessage in project spring-integration by spring-projects.

the class DirectMessageReceivingMessageSourceTests method demoReceiveDm.

@SuppressWarnings("unchecked")
@Test
@Ignore
public void demoReceiveDm() throws Exception {
    PropertiesFactoryBean pf = new PropertiesFactoryBean();
    pf.setLocation(new ClassPathResource("sample.properties"));
    pf.afterPropertiesSet();
    Properties prop = pf.getObject();
    TwitterTemplate template = new TwitterTemplate(prop.getProperty("z_oleg.oauth.consumerKey"), prop.getProperty("z_oleg.oauth.consumerSecret"), prop.getProperty("z_oleg.oauth.accessToken"), prop.getProperty("z_oleg.oauth.accessTokenSecret"));
    DirectMessageReceivingMessageSource tSource = new DirectMessageReceivingMessageSource(template, "foo");
    tSource.afterPropertiesSet();
    for (int i = 0; i < 50; i++) {
        Message<DirectMessage> message = (Message<DirectMessage>) tSource.receive();
        if (message != null) {
            DirectMessage tweet = message.getPayload();
            logger.info(tweet.getSender().getScreenName() + " - " + tweet.getText() + " - " + tweet.getCreatedAt());
        }
    }
}
Also used : TwitterTemplate(org.springframework.social.twitter.api.impl.TwitterTemplate) DirectMessage(org.springframework.social.twitter.api.DirectMessage) Message(org.springframework.messaging.Message) DirectMessage(org.springframework.social.twitter.api.DirectMessage) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 PropertiesFactoryBean (org.springframework.beans.factory.config.PropertiesFactoryBean)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Message (org.springframework.messaging.Message)1 DirectMessage (org.springframework.social.twitter.api.DirectMessage)1 TwitterTemplate (org.springframework.social.twitter.api.impl.TwitterTemplate)1