问题描述
我正在尝试使用 twitter4j3.0.3 和 Scala 传输推文,但它给了我这些错误.这是我的代码:
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()
}
}
和错误:带有替代方法的重载方法值 addListener:(twitter4j.RawStreamListener)单元(twitter4j.SiteStreamsListener)单元(twitter4j.StatusListener)单元(twitter4j.UserStreamListener)单元不能应用于 (ch.qos.logback.core.status.StatusListener)twitterStream.addListener(simpleStatusListener)^
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) ^
推荐答案
您导入了错误的 StatusListener 接口.而不是
You're importing the wrong StatusListener interface. Instead of
import ch.qos.logback.core.status.StatusListener
你需要
导入 twitter4j.StatusListener
这篇关于尝试使用 twitter4j3.0.3 流式传输推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!