Announcement Announcement Module
Collapse
No announcement yet.
Support for Twitter Streaming API Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Support for Twitter Streaming API

    Hi,

    Do you have support for Twitter streaming API and perhaps a working example?

    thanks

  • #2
    There's a good start on the Twitter streaming API work in the latest snapshot builds. I do not currently have an example of its use outside of tests, but I should bake one up. I'll try to get an example out there soon. In the meanwhile, here's some code that I've been using to observationally test it:

    Code:
    		TwitterTemplate twitter = new TwitterTemplate("YR571S2JiVBOFyJS5MEg", "Kb8hS0luftwCJX3qVoyiLUMfZDtK1EozFoUkjNLUMx4", "7078572-srXzIDwmIc0lg69TBR0rLr9TqHYJiRqPIv14gunpk", "xfnQDjYEcdTCcYWeLcJyGuszQG9R5UnG5TrvtfG33BU");
    		List<StreamListener> listeners = new ArrayList<StreamListener>();
    		StreamListener listener = new StreamListener() {			
    			public void onTweet(Tweet tweet) {
    				System.out.println("TWEET:  " + tweet.getFromUser() + "   -   " + tweet.getText());
    			}
    			
    			public void onLimit(int numberOfLimitedTweets) {
    				System.out.println("LIMIT:  " + numberOfLimitedTweets);
    			}
    			
    			public void onDelete(StreamDeleteEvent deleteEvent) {
    				System.out.println("DELETE:  " + deleteEvent.getTweetId());
    			}
    			
    			public void onWarning(StreamWarningEvent warnEvent) {
    				System.out.println("WARNING:  " + warnEvent.getCode());
    			}
    		};
    		listeners.add(listener);
    		UserStreamParameters params = new UserStreamParameters().with(WithOptions.FOLLOWINGS).includeReplies(true);
    //		Stream userStream = twitter.streamingOperations().sample(listeners);
    		Stream userStream = twitter.streamingOperations().filter("Disney", listeners);
    //		twitter.streamingOperations().sample(listeners);
    		Thread.sleep(10000);
    		userStream.stop();
    It's non-ideal as an example, but it should give you an idea of how to use the API binding.

    I've had the streaming code in GitHub and snapshot builds for over a month while I fine-tune it. So far, nobody has given me any feedback on it. If you try it out, *PLEASE* let me know what you think. It's always better to get feedback from the community while it's still in snapshot or milestone releases than to get it later when it's in a GA release.

    Comment


    • #3
      Craig - can you provide me the exact snapshot version for maven dependency and the maven repository where it can be located?

      Comment


      • #4
        As with most Spring projects, snapshots can be found at http://repo.springsource.org/snapshot/. Specifically, the pom.xml entries should be:

        Code:
        <dependency>
          <groupId>org.springframework.social</groupId>
          <artifactId>spring-social-twitter</artifactId>
          <version>1.1.0.BUILD-SNAPSHOT</version>
        </dependency>
        ...and then in your repositories entries:

        Code:
        <repository>
          <id>org.springframework.maven.snapshot</id>
          <name>Spring Maven Snapshot Repository</name>
          <url>http://repo.springsource.org/snapshot</url>
          <releases><enabled>false</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
        Although the Spring Social Showcase doesn't use Twitter streaming, you can look at its pom.xml file to see what's needed.

        If you're using Gradle, then it's slightly easier:

        Code:
        compile ("org.springframework.social:spring-social-twitter:1.1.0.BUILD-SNAPSHOT")
        ...and in your repositories declaration:

        Code:
        repositories {
          maven { url 'http://repo.springsource.org/snapshot' }
        }

        Comment


        • #5
          Correct me if I'm wrong and I very well may be, but I don't believe the Streaming API binding is in any of the versions of Spring Social Twitter, including the latest snapshot build (1.1.0.BUILD-20130530.081517-388).

          Assuming I was doing something wrong, I went ahead and manually checked the source as well as the docs in hopes of finding it.

          Source: http://repo.springsource.org/snapsho...88-sources.jar
          Docs: http://repo.springsource.org/snapsho...7-388-docs.zip

          If I'm missing something, I apologize and thanks in advance for pointing me in the right direction. If not, I'd appreciate it if you could include it in the next snapshot as it is pivotal to my next leg of development, and I'd rather not implement twitter4j only to remove it when Spring has a better binding.

          Comment


          • #6
            Ah...my mistake. I had assumed that I had pushed it to GitHub, but I hadn't. I've been working on it in a separate branch on my local machine and never merged it and pushed it to GitHub. I'll see about doing that sometime today and let you know.

            Comment


            • #7
              I just merged the streaming stuff into the master branch and the snapshot is building as I write this.

              I had some unfinished work on upgrading to Jackson 2 that I had to complete before I could merge in the streaming stuff, or else I'd have finished it earlier today.

              Comment

              Working...
              X