Streaming tweets with Hosebird

141 views Asked by At

I'm trying to get a stream of public tweets using Hosebird (https://github.com/twitter/hbc), which I'm completely new to. I tried using their 'Quickstart' example, just to get an idea of what the streaming is like, so I copied the example code. The only changes I made were getting rid of the 'followings' variable, and filling in the proper OAuth information.

After connecting using hosebirdClient.connect(), I added this code in an attempt to print one tweet:

String msg = null;
   try {
      msg = msgQueue.take();
   } catch (InterruptedException e) {
      e.printStackTrace();
   }
System.out.println(msg);

The code is free of errors, but then stays on the line String msg = msgQueue.take() forever, instead of producing a tweet. Any ideas on what I'm doing wrong?

1

There are 1 answers

0
user On BEST ANSWER

I ended up figuring it out, so hopefully I can help anyone else who has this issue in the future. My code was correct, but I had to use Maven instead of making a normal Java project. In Maven, I needed to install the exec plugin by adding this to the POM file:

<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.4.0</version> <configuration> <mainClass>Test.Twitter2.App</mainClass> </configuration> </plugin> </plugins> </build>

After that, running the program as a Maven build with the goal of exec:java worked perfectly.