我正致力于Twitter数据上的火花流媒体计划。 在我的代码中,
object TwitterDataAnalysis {
def main(args: Array[String]) {
if(args.length < 4) {
System.err.println("Usage: TwitterPopularTags <consumer key> <consumer secret> " +
"<access token> <access token secret> [<filters>]")
System.exit(1)
}
val Array(consumerKey, consumerSecret, accessToken, accessTokenSecret) = args.take(4)
val filters = args.takeRight(args.length - 4)
System.setProperty("twitter4j.oauth.consumerKey", consumerKey)
System.setProperty("twitter4j.oauth.consumerSecret", consumerSecret)
System.setProperty("twitter4j.oauth.accessToken", accessToken)
System.setProperty("twitter4j.oauth.accessTokenSecret", accessTokenSecret)
val sparkConf = new SparkConf().setAppName("Twitter's trending HashTags").setMaster("local[2]")
val ssc = new StreamingContext(sparkConf,Seconds(5))
val stream = TwitterUtils.createStream(ssc, None, filters)
val tweets = stream.flatMap(tweet => tweet.getText.split(" ")).filter(_.startsWith("#"))
}
}
我还没有完成程序,因为我收到错误: val tweets = stream.flatMap(tweet =&gt; tweet.getText.split(&#34;&#34;) ).filter(_ startsWith(&#34;#&#34))即可。
它说:值getText不是类型参数T 的成员 这些是我的pom.xml文件中的依赖项。
<!-- Spark Dependency -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.twitter4j/twitter4j-stream -->
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-stream</artifactId>
<version>4.0.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-streaming-twitter_2.10 -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-twitter_2.10</artifactId>
<version>1.6.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-streaming_2.10 -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_2.10</artifactId>
<version>2.1.1</version>
</dependency>
我的导入声明:
import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.SparkContext
import org.apache.spark.streaming.twitter._
import org.apache.spark.SparkConf
import StreamingContext._
任何人都可以说出我做的错误是什么?由于我之后没有得到任何功能,我无法进一步加粗。我需要在代码中更改什么内容吗?