trying to stream tweets with twitter4j3.0.3

泄露秘密 提交于 2019-12-13 01:17:19

问题


I am trying to stream tweets with twitter4j3.0.3 with scala but it gives me these errors. Here is my code:

   import twitter4j._
   import ch.qos.logback.core.status.StatusListener
   import twitter4j.conf.ConfigurationBuilder
   import ch.qos.logback.core.status

   object stream {



  def main(args: Array[String]) {
  val cb: ConfigurationBuilder = new ConfigurationBuilder
  cb.setDebugEnabled(true)
   .setOAuthConsumerKey("1")
   .setOAuthConsumerSecret("1")
   .setOAuthAccessToken("1")
   .setOAuthAccessTokenSecret("1")

 def simpleStatusListener:StatusListener =new StatusListener() {
  def addStatusEvent(status: Status) {println(x = status.getText)}


  def onStatus(status: Status) { println(x = status.getText) }
  def onDeletionNotice(statusDeletionNotice: StatusDeletionNotice) {}
  def onTrackLimitationNotice(numberOfLimitedStatuses: Int) {}
  def onException(ex: Exception) { ex.printStackTrace }
  def onScrubGeo(arg0: Long, arg1: Long) {}
  def onStallWarning(warning: StallWarning) {}

 }

 val twitterStream:TwitterStream= new TwitterStreamFactory(cb.build).getInstance()

 twitterStream.addListener(simpleStatusListener)
 twitterStream.sample()
 }
 }

and the error: overloaded method value addListener with alternatives: (twitter4j.RawStreamListener)Unit (twitter4j.SiteStreamsListener)Unit (twitter4j.StatusListener)Unit (twitter4j.UserStreamListener)Unit cannot be applied to (ch.qos.logback.core.status.StatusListener) twitterStream.addListener(simpleStatusListener) ^


回答1:


You're importing the wrong StatusListener interface. Instead of

import ch.qos.logback.core.status.StatusListener

You need

import twitter4j.StatusListener



来源:https://stackoverflow.com/questions/18115896/trying-to-stream-tweets-with-twitter4j3-0-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!