Created
November 4, 2011 03:24
-
-
Save tototoshi/1338586 to your computer and use it in GitHub Desktop.
Twitter4jでストリーミングAPIを使ってみる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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