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.
Printable View
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.
It is a pretty new module and still in works. We'll be publishing samples within few weeks.
I see.. thank you!
@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:
Here is the test: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"/>
This is just a simple test, you can have it much prettier using a message gateway :)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);
}
I'm still working on reading tweets.....
Nick.
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.
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:
And twitterAnnouncer looks like ( I'm sure you already know how it looks :) ):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"/>
Please let me know if you spot something wrong....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());
}
Thanks a lot!
Nick
I was running the example with property auto-startup="false" even though the example I posted had it as "true" :mad:
Well.... It is working now.
Thanks,
Nick
default is 'true', so you can omit it all together unless you want it 'false'