使用 Hosebird 流式传输推文
Streaming tweets with Hosebird
我正在尝试使用 Hosebird (https://github.com/twitter/hbc) 获取 public 推文流,我对此完全陌生。我尝试使用他们的 'Quickstart' 示例,只是为了了解流式传输是什么样的,所以我复制了示例代码。我所做的唯一更改是删除 'followings' 变量,并填写正确的 OAuth 信息。
使用 hosebirdClient.connect()
连接后,我添加了此代码以尝试打印一条推文:
String msg = null;
try {
msg = msgQueue.take();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(msg);
代码没有错误,但会永远停留在 String msg = msgQueue.take()
线上,而不是生成推文。对我做错了什么有什么想法吗?
我最终弄明白了,所以希望我能帮助以后遇到这个问题的任何人。我的代码是正确的,但我不得不使用 Maven 而不是制作一个普通的 Java 项目。在 Maven 中,我需要通过将其添加到 POM 文件来安装 exec 插件:
<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>
在那之后,运行 以 exec:java 为目标的 Maven 构建程序完美运行。
我正在尝试使用 Hosebird (https://github.com/twitter/hbc) 获取 public 推文流,我对此完全陌生。我尝试使用他们的 'Quickstart' 示例,只是为了了解流式传输是什么样的,所以我复制了示例代码。我所做的唯一更改是删除 'followings' 变量,并填写正确的 OAuth 信息。
使用 hosebirdClient.connect()
连接后,我添加了此代码以尝试打印一条推文:
String msg = null;
try {
msg = msgQueue.take();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(msg);
代码没有错误,但会永远停留在 String msg = msgQueue.take()
线上,而不是生成推文。对我做错了什么有什么想法吗?
我最终弄明白了,所以希望我能帮助以后遇到这个问题的任何人。我的代码是正确的,但我不得不使用 Maven 而不是制作一个普通的 Java 项目。在 Maven 中,我需要通过将其添加到 POM 文件来安装 exec 插件:
<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>
在那之后,运行 以 exec:java 为目标的 Maven 构建程序完美运行。