spark、scala、推特流媒体

hmae6n7t  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(360)

我在ubuntu home path中编写了一个scala脚本.scala,并对twitter应用程序中的所有oauth值进行了硬编码:

import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.SparkContext._
import org.apache.spark.streaming.twitter._
import org.apache.spark.SparkConf

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 filters="Raj"
val sparkConf = new SparkConf().setAppName("TwitterPopularTags").setMaster("local[2]")
val ssc = new StreamingContext(sparkConf, Seconds(2))
val stream = TwitterUtils.createStream(ssc, None, filters)

我执行的是

$Spark_bin-2.7> cat abc.scala | ./spark-shell

它一直持续到streamingcontext。但当它到达twitterutils时,它会给出错误的读数:
错误:未找到:twitterutils
我下载了最新的spark 2.0.1。你能一步一步地指出设置或文件吗?

kg7wmglp

kg7wmglp1#

添加org.apache。spark:spark-streaming-twitter_2.11:1.6.1Spark壳状

$Spark_bin-2.7> cat abc.scala | ./spark-shell --packages org.apache.spark:spark-streaming-twitter_2.11:1.6.1

使用此方法

import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.SparkContext._
import org.apache.spark.streaming.twitter._
import org.apache.spark.SparkConf

System.setProperty("twitter4j.oauth.consumerKey", consumerKey)
System.setProperty("twitter4j.oauth.consumerSecret", consumerSecret)
System.setProperty("twitter4j.oauth.accessToken", accessToken)
System.setProperty("twitter4j.oauth.accessTokenSecret", accessTokenSecret)

sc.stop()
val filters="Raj"
val sparkConf = new SparkConf().setAppName("TwitterPopularTags").setMaster("local[2]")
val sc = new SparkContext(sparkConf)
val ssc = new StreamingContext(sc, Seconds(2))
val stream = TwitterUtils.createStream(ssc, None, filters)

相关问题