Announcement Announcement Module
Collapse
No announcement yet.
Sample using Twitter-component? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    It is a pretty new module and still in works. We'll be publishing samples within few weeks.

    Comment


    • #3
      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?

      Comment


      • #4
        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

        Comment


        • #5
          I see.. thank you!

          Comment


          • #6
            @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, 02:09 PM.

            Comment


            • #7
              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.

              Comment


              • #8
                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

                Comment


                • #9
                  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

                  Comment


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

                    Comment

                    Working...
                    X