从特定推特使用中提取推文 [英] Extracts tweets from a specific twitter use

查看:42
本文介绍了从特定推特使用中提取推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Scala 提取特定用户的推文.我的代码如下:

I want to extracts tweets from a specific user using scala. My code is given below:

import twitter4j._
import twitter4j.Status
import collection.JavaConversions._
import org.apache.spark.streaming.twitter._
import org.apache.spark.SparkConf
import org.apache.spark._

val CONSUMER_KEY = "hidden"
val CONSUMER_SECRET = "hidden"
val ACCESS_TOKEN = "hidden"
val ACCESS_TOKEN_SECRET = "hidden"

System.setProperty("twitter4j.oauth.consumerKey", CONSUMER_KEY)
System.setProperty("twitter4j.oauth.consumerSecret", CONSUMER_SECRET)
System.setProperty("twitter4j.oauth.accessToken", ACCESS_TOKEN)
System.setProperty("twitter4j.oauth.accessTokenSecret", ACCESS_TOKEN_SECRET)

val twitter = new TwitterFactory().getInstance
val statuses = twitter.search(new Query("aTwitterUser")).getTweets

statuses.foreach(status => println(status.getText + "\n"))

通过使用上面的代码,我能够获取指定用户的所有推文以及用户的推文.那并没有解决我的问题.我只想打印用户制作的推文.任何帮助将不胜感激.

By using the above code I am able to get all tweets in with specified user is mentioned plus tweets of user. That did not resolve my problem. I only want to print tweets made by user. Any help will be appreciated.

问候!

推荐答案

参见 http 上的第 4 点://twitter4j.org/en/code-examples.html

使用来源:"查询

java代码:

 // The factory instance is re-useable and thread safe.
    Twitter twitter = TwitterFactory.getSingleton();
    Query query = new Query("source:twitter4j yusukey");
    QueryResult result = twitter.search(query);
    for (Status status : result.getTweets()) {
        System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
    }

更多查询运算符:https://dev.twitter.com/rest/public/搜索

特别注意'from:'操作符:

special attention to 'from:' operator:

    Query query = new Query("from:twitter4j yusukey");

这篇关于从特定推特使用中提取推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆