मैं ट्विटर 4j ट्विटरस्ट्रीम ऑब्जेक्ट के माध्यम से ट्विटर पर सभी ट्वीट्स प्राप्त करने का प्रयास कर रहा हूं। मुझे यकीन नहीं है कि मुझे सभी ट्वीट मिल रही हैं। देरी का परीक्षण करने के बाद स्ट्रीमिंग एपीआई ट्वीट लौटाता है, मैंने ट्विटर पर अपने खाते से एक ट्वीट पोस्ट किया। लेकिन मुझे लंबे समय के बाद भी यह ट्वीट नहीं मिला।ट्विटर 4j ट्विटरस्ट्रीम को सभी ट्वीट्स नहीं मिलते हैं
क्या twitter4j ट्विटर पर पोस्ट किए गए प्रत्येक ट्वीट को पकड़ता है या यह ट्वीट्स का एक अच्छा प्रतिशत खो देता है? या मैं यहाँ कुछ गलत कर रहा हूँ? यहाँ कोड है कि मैं ट्वीट्स प्राप्त करने के लिए उपयोग कर रहा हूँ है:
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();