Last active
December 19, 2015 04:39
-
-
Save torao/5898602 to your computer and use it in GitHub Desktop.
How to retrieve raw JSON status from Twitter Sample Stream API using twitter4j. / twitter4j を使用して Twitter Sample API から生の JSON を取得する方法。
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
import twitter4j._ | |
import twitter4j.conf._ | |
import twitter4j.json._ | |
object Stream extends RawStreamListener { | |
def main(args:String):Unit = { | |
val conf = new ConfigurationBuilder() | |
.setDebugEnabled(true) | |
.setOAuthConsumerKey("xxxx") | |
.setOAuthConsumerSecret("xxxx") | |
.setOAuthAccessToken("xxxx") | |
.setOAuthAccessTokenSecret("xxxx") | |
.build() | |
val stream = new TwitterStreamFactory(conf).getInstance() | |
stream.addListener(this) | |
stream.sample() | |
} | |
def onMessage(rawString:String):Unit = { | |
// You can restore Status instance by DataObjectFactory. | |
// val status = DataObjectFactory.createStatus(rawString) | |
System.out.println(rawString) | |
} | |
def onException(ex:Exception):Unit = { | |
ex.printStackTrace() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment