Created
March 26, 2015 11:34
-
-
Save ara-ta3/c075573901e091210b0b to your computer and use it in GitHub Desktop.
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
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