Skip to content

Instantly share code, notes, and snippets.

@tototoshi
Created November 4, 2011 03:24
Show Gist options
  • Save tototoshi/1338586 to your computer and use it in GitHub Desktop.
Save tototoshi/1338586 to your computer and use it in GitHub Desktop.
Twitter4jでストリーミングAPIを使ってみる
import twitter4j._
import conf._
/* build.sbt
scalaVersion := "2.9.1"
libraryDependencies ++= Seq(
"org.twitter4j" % "twitter4j-core" % "2.2.5",
"org.twitter4j" % "twitter4j-stream" % "2.2.5"
)
*/
object Main {
def main(args: Array[String]) = {
val listener: StatusListener = new StatusListener {
def onStatus(status: Status) = {
println(status.getUser.getName + " : " + status.getText)
}
def onDeletionNotice(s: StatusDeletionNotice) = {}
def onTrackLimitationNotice(numberOfLimitedStatuses: Int) = {}
def onException(ex: Exception) = ex.printStackTrace()
def onScrubGeo(userId: Long, upToStatusId: Long) = {}
}
val configurationBuilder = new ConfigurationBuilder()
val conf = configurationBuilder.setUser("YOUR USER ID")
.setPassword("YOUR PASSWORD")
.build
val twitterStream: TwitterStream = new TwitterStreamFactory(conf).getInstance
val statusStream: StatusStream = twitterStream.getSampleStream()
while (true) {
statusStream.next(listener)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment