使用 twitter api 和 spark 搜索特定关键字
Search for specific key word using twitter api and spark
我正在尝试这段代码,并将#替换为#Apple。
val ssc = new StreamingContext("local[*]", "PopularHashtags", Seconds(1))
val tweets = TwitterUtils.createStream(ssc, None)
val statuses = tweets.map(status => status.getText())
val tweetwords = statuses.flatMap(tweetText => tweetText.split(" "))
val hashtags = tweetwords.filter(word => word.startsWith("#"))
val hashtagKeyValues = hashtags.map(hashtag => (hashtag, 1))
val hashtagCounts = hashtagKeyValues.reduceByKeyAndWindow( (x,y) => x + y, (x,y) => x - y, Seconds(1000), Seconds(1))
val sortedResults = hashtagCounts.transform(rdd => rdd.sortBy(x => x._2, false))
sortedResults.print
但是我没有得到任何结果。
此流式传输是否对推文的数量以及将从哪个区域获取推文有一些限制?
我也尝试在我的推特帐户中寻找#OPPO,因为这是趋势,所以我尝试寻找它,但仍然没有得到任何结果。
val ssc = new StreamingContext("local[*]", "PopularHashtags", Seconds(1))
//The keyword you want to look for can be specified in a sequence as follows
var seq:Seq[String] = Seq("#Rajasthan","#Apple")
val tweets = TwitterUtils.createStream(ssc, None, seq)
val statuses = tweets.map(status => status.getText())
val tweetwords = statuses.flatMap(tweetText => tweetText.split(" "))
val hashtags = tweetwords.filter(word=>word.contains("#"))
val hashtagKeyValues = hashtags.map(hashtag => (hashtag, 1))
val hashtagCounts = hashtagKeyValues.reduceByKeyAndWindow( (x,y) => x + y, (x,y) => x - y, Seconds(1000), Seconds(1))
val sortedResults = hashtagCounts.transform(rdd => rdd.sortBy(x => x._2, false))
sortedResults.print
我正在尝试这段代码,并将#替换为#Apple。
val ssc = new StreamingContext("local[*]", "PopularHashtags", Seconds(1))
val tweets = TwitterUtils.createStream(ssc, None)
val statuses = tweets.map(status => status.getText())
val tweetwords = statuses.flatMap(tweetText => tweetText.split(" "))
val hashtags = tweetwords.filter(word => word.startsWith("#"))
val hashtagKeyValues = hashtags.map(hashtag => (hashtag, 1))
val hashtagCounts = hashtagKeyValues.reduceByKeyAndWindow( (x,y) => x + y, (x,y) => x - y, Seconds(1000), Seconds(1))
val sortedResults = hashtagCounts.transform(rdd => rdd.sortBy(x => x._2, false))
sortedResults.print
但是我没有得到任何结果。
此流式传输是否对推文的数量以及将从哪个区域获取推文有一些限制? 我也尝试在我的推特帐户中寻找#OPPO,因为这是趋势,所以我尝试寻找它,但仍然没有得到任何结果。
val ssc = new StreamingContext("local[*]", "PopularHashtags", Seconds(1))
//The keyword you want to look for can be specified in a sequence as follows
var seq:Seq[String] = Seq("#Rajasthan","#Apple")
val tweets = TwitterUtils.createStream(ssc, None, seq)
val statuses = tweets.map(status => status.getText())
val tweetwords = statuses.flatMap(tweetText => tweetText.split(" "))
val hashtags = tweetwords.filter(word=>word.contains("#"))
val hashtagKeyValues = hashtags.map(hashtag => (hashtag, 1))
val hashtagCounts = hashtagKeyValues.reduceByKeyAndWindow( (x,y) => x + y, (x,y) => x - y, Seconds(1000), Seconds(1))
val sortedResults = hashtagCounts.transform(rdd => rdd.sortBy(x => x._2, false))
sortedResults.print