[英]Why is twitter4j TwitterStream not filtering user's tweets?
[英]Twitter4j TwitterStream doesn't get all tweets
我試圖通過twitter4j TwitterStream對象獲取Twitter上的所有推文。 我不確定我收到了所有的推文。 為了測試流API返回推文之后的延遲,我在twitter上發布了一條推文。 但即使很長一段時間后我也沒有收到這條推文。
twitter4j是否會抓住Twitter上發布的每條推文,或者它的推文丟失率很高? 或者我在這里做錯了什么? 這是我用來獲取推文的代碼:
StatusListener listener = new StatusListener(){
int countTweets = 0; // Count to implement batch processing
public void onStatus(Status status) {
countTweets ++;
StatusDto statusDto = new StatusDto(status);
session.saveOrUpdate(statusDto);
// Save 1 round of tweets to the database
if (countTweets == BATCH_SIZE) {
countTweets = 0;
session.flush();
session.clear();
}
}
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {}
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {}
public void onException(Exception ex) {
ex.printStackTrace();
}
public void onScrubGeo(long arg0, long arg1) {
// TODO Auto-generated method stub
}
};
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(Twitter4jProperties.CONSUMER_KEY)
.setOAuthConsumerSecret(Twitter4jProperties.CONSUMER_SECRET)
.setOAuthAccessToken(Twitter4jProperties.ACCESS_TOKEN)
.setOAuthAccessTokenSecret(Twitter4jProperties.ACCESS_TOKEN_SECRET);
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
twitterStream.addListener(listener);
session = HibernateUtil.getSessionFactory().getCurrentSession();
transaction = session.beginTransaction();
// sample() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
twitterStream.sample();
我對此持開放態度,但我認為它的作用是這樣的...
Streaming API僅提供非合作伙伴的推文樣本。 它是“花園軟管”,而不是一些Twitter合作伙伴得到的“firehose”。 但您可以申請完全訪問權限。
.sample()給出了這個“花園軟管”。 您的Twitter帳戶將無法訪問firehose,但我認為如果您確實有訪問權限,則會有一個用於firehose的twitterStream。
在此頁面上搜索“狀態/樣本”以獲取具體信息: https : //dev.twitter.com/docs/streaming-api/methods
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.