Skip to content

Instantly share code, notes, and snippets.

@ara-ta3
Created March 26, 2015 11:34
Show Gist options
  • Save ara-ta3/c075573901e091210b0b to your computer and use it in GitHub Desktop.
Save ara-ta3/c075573901e091210b0b to your computer and use it in GitHub Desktop.
package my.twitter
import twitter4j._
import conf._
/*
* ref http://tototoshi.hatenablog.com/entry/20111104/1320377494
* libraryDependencies ++= Seq(
* "org.twitter4j" % "twitter4j-core" % "2.2.5",
* "org.twitter4j" % "twitter4j-stream" % "2.2.5"
* )
*/
object Sample extends App {
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.setOAuthConsumerKey("XXX")
.setOAuthConsumerSecret("XXX")
.setOAuthAccessToken("XXX")
.setOAuthAccessTokenSecret("XXX")
.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