Created
March 30, 2016 13:20
-
-
Save mehalter/363192861d0f999b2178f859f23102e7 to your computer and use it in GitHub Desktop.
Twitter API Stream
This file contains 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 com.mehalter | |
import twitter4j._ | |
object StatusStreamer { | |
def main(args: Array[String]): Unit = { | |
val twitterStream = new TwitterStreamFactory(Util.config).getInstance | |
twitterStream.addListener(Util.simpleStatusListener) | |
val austinBox = Array(Array(-97.8, 30.25), Array(-97.65, 30.35)) | |
//twitterStream.sample //sample of tweets | |
//twitterStream.filter(new FilterQuery(Array(2803971569L))) //Twitter IDs | |
//twitterStream.filter(new FilterQuery().track(Array("computer science"))) //Track by specific terms | |
twitterStream.filter(new FilterQuery().locations(austinBox)) //filter by locations | |
Thread.sleep(10000) //how long to be streaming | |
twitterStream.cleanUp | |
twitterStream.shutdown | |
} | |
} | |
object Util { | |
val config = new twitter4j.conf.ConfigurationBuilder() | |
.setOAuthConsumerKey("lxcQj5cTHanXBFpJTW42hy62i") | |
.setOAuthConsumerSecret("WbFyYpN1D1d3uAVeK80sbY0bxCuxJz7zL2aCeJLXAG3VLwIqQL") | |
.setOAuthAccessToken("2803971569-RetGcDFtpV7of6Akx0m69JocfYvuEQx0ykzuQVj") | |
.setOAuthAccessTokenSecret("RAn8Ijemr4ZgR3rgj4F4N4zDNN9M0ohNRGF7z5v8cXDGy") | |
.build() | |
def simpleStatusListener = new StatusListener {override def onStallWarning(warning: StallWarning): Unit = ??? | |
override def onDeletionNotice(statusDeletionNotice: StatusDeletionNotice): Unit = {} | |
override def onScrubGeo(userId: Long, upToStatusId: Long): Unit = {} | |
override def onStatus(status: Status): Unit = println(status.getText) | |
override def onTrackLimitationNotice(numberOfLimitedStatuses: Int): Unit = {} | |
override def onException(ex: Exception): Unit = {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment