Results 1 to 10 of 10

Thread: Sample using Twitter-component?

  1. #1
    Join Date
    Sep 2010
    Posts
    1

    Default Sample using Twitter-component?

    Hi

    I'm new to SI and not entirely sure where to find up to date samples etc. I can see that there's a twitter jar in M7 release but I can't find any code where it's used. Also looked in the sourcecode to see if any tests were there.

    Regards.

  2. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    It is a pretty new module and still in works. We'll be publishing samples within few weeks.

  3. #3
    Join Date
    Sep 2010
    Posts
    11

    Default

    Quote Originally Posted by ankelee View Post
    Hi

    I'm new to SI and not entirely sure where to find up to date samples etc. I can see that there's a twitter jar in M7 release but I can't find any code where it's used. Also looked in the sourcecode to see if any tests were there.

    Regards.
    Hi im new here too.. an i have twitter account. What is M7 means?

  4. #4
    Join Date
    Nov 2008
    Location
    Swansea, Wales
    Posts
    202

    Default

    Quote Originally Posted by maxellwill View Post
    Hi im new here too.. an i have twitter account. What is M7 means?
    M7 means Milestone 7. It's a milestone build on the way to the release of Spring Integration 2.0

  5. #5
    Join Date
    Sep 2010
    Posts
    11

    Default

    I see.. thank you!

  6. #6

    Default

    @ankelee

    I was able to get a simple example that tweeted to my account a direct message (TwitterHeaders.DM_TARGET_USER_ID) using the twitter outbound-update-channel-adapter. You can use IN_REPLY_TO_STATUS_ID header to reply to specific tweets.

    Here is the config:

    HTML Code:
    <twitter:twitter-connection id="tc"
                                access-token="${twitter.oauth.accessToken}"
                                access-token-secret="${twitter.oauth.accessTokenSecret}"
                                consumer-key="${twitter.oauth.consumerKey}"
                                consumer-secret="${twitter.oauth.consumerSecret}"/>
    
    <channel id="out"/> 
    	
    <twitter:outbound-update-channel-adapter twitter-connection="tc" channel="out"/> 
    
    <context:property-placeholder location="classpath:META-INF/props/twitter.properties" ignore-unresolvable="true"/>
    Here is the test:
    Code:
    	@Value("#{out}") private MessageChannel channel;
    	
    	@Test
    	public void shouldTweet() {
    		MessagingTemplate messagingTemplate = new MessagingTemplate();
    
    		MessageBuilder<String> mb = MessageBuilder.withPayload("tweet tweet from my spring app :)").setHeader(TwitterHeaders.DM_TARGET_USER_ID, "@twitterUser"); 
    
    		Message<String> m = mb.build(); 
    		messagingTemplate.send(this.channel, m); 
    	}
    This is just a simple test, you can have it much prettier using a message gateway

    I'm still working on reading tweets.....


    Nick.
    Last edited by nicolas.loriente; Nov 3rd, 2010 at 01:09 PM.

  7. #7
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Well let me know if you have any problem reading
    Also, just in case you are still on M7, upgrade to RC1. A lot of refactoring was done to twitter.

  8. #8

    Default

    Thanks for the comment Oleg.

    Yes, I am running with 2.0.0.CR1

    Funny that you mention.... I do have problems reading

    I tried last night and I was not getting any reads from the timeline... then I tried to post and that worked.

    Still haven't figure out what am I doing wrong when trying to read the tweets

    This is my spring conf taken from spring-integration-twitter project tests:

    HTML Code:
    <twitter:twitter-connection id="tc"
                                access-token="${twitter.oauth.accessToken}"
                                access-token-secret="${twitter.oauth.accessTokenSecret}"
                                consumer-key="${twitter.oauth.consumerKey}"
                                consumer-secret="${twitter.oauth.consumerSecret}"/>
     
    <twitter:inbound-mention-channel-adapter id="mentionAdapter" 
                                             twitter-connection="tc" 
                                             channel="inbound_mentions" 
                                             auto-startup="true">
        <poller fixed-rate="5000" max-messages-per-poll="3"/>
    </twitter:inbound-mention-channel-adapter>
    <service-activator input-channel="inbound_mentions" ref="twitterAnnouncer" method="mention"/>
    
    <twitter:inbound-dm-channel-adapter id="dmAdapter" 
                                        twitter-connection="tc" 
                                        channel="inbound_dm" 
                                        auto-startup="true">
         <poller fixed-rate="5000" max-messages-per-poll="3"/>
    </twitter:inbound-dm-channel-adapter>
    <service-activator input-channel="inbound_dm" ref="twitterAnnouncer" method="dm"/>
    
    <twitter:inbound-update-channel-adapter id="updateAdapter" 
                                            twitter-connection="tc" 
                                            channel="inbound_updates" 
                                            auto-startup="true">
        <poller fixed-rate="5000" max-messages-per-poll="3"/>
    </twitter:inbound-update-channel-adapter>
    <service-activator input-channel="inbound_updates" ref="twitterAnnouncer" method="updates"/>
    
    <channel id="inbound_dm"/>
    <channel id="inbound_mentions"/>
    <channel id="inbound_updates"/>
    	
    <beans:bean id="twitterAnnouncer" class="org.spring.integration.twitter.TwitterAnnouncer"/>
    And twitterAnnouncer looks like ( I'm sure you already know how it looks ):
    Code:
    public void dm(DirectMessage directMessage) {
        System.out.println("A direct message has been received from "
            + directMessage.getSender().getScreenName() + " with text "
    		+ directMessage.getText());
    }
    
    public void mention(Status s) {
        System.out.println("A tweet mentioning (or replying) to "
            + "you was received having text " + s.getText() + " from "
    		+ s.getSource());
    }
    
    public void updates(Status t) {
        System.out.println("Received timeline update: " + t.getText()
      	+ " from " + t.getSource());
    }
    Please let me know if you spot something wrong....

    Thanks a lot!

    Nick

  9. #9

    Default

    I was running the example with property auto-startup="false" even though the example I posted had it as "true"

    Well.... It is working now.

    Thanks,

    Nick

  10. #10
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    default is 'true', so you can omit it all together unless you want it 'false'

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •