Livro Big Data - Erro no exemplo de captura tweets

big-data

#1

Boa noite a todos!

Estou fazendo o exemplo de captura de tweets do livro Big Data e está apresentando o erro abaixo durante a execução:

[Wed Apr 25 00:08:57 BRT 2018]Establishing connection.
[Wed Apr 25 00:09:30 BRT 2018]Connection established.
[Wed Apr 25 00:09:30 BRT 2018]Receiving status stream.
[Wed Apr 25 00:31:15 BRT 2018]Stream closed.
Exception in thread “Twitter Stream consumer-1[Receiving stream]” java.lang.UnsupportedOperationException: Not supported yet.
at twitterapp.TwitterApp$1.onException(TwitterApp.java:71)
at twitter4j.StatusStreamBase.onException(StatusStreamBase.java:401)
at twitter4j.TwitterStreamImpl$TwitterStreamConsumer.run(TwitterStreamImpl.java:574)

Segue o código, a princípio idêntico ao do livro:

package twitterapp;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoException;
import java.net.UnknownHostException;
import twitter4j.*;
import twitter4j.conf.ConfigurationBuilder;

/**
*

  • @author USER
    */
    public class TwitterApp {
    private ConfigurationBuilder cb;
    private DB banco;
    private DBCollection collection;

    public void capturaTweets() throws InterruptedException {
    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();

     StatusListener listener = new StatusListener() {
         @Override
         public void onStatus(Status status) {
             BasicDBObject obj = new BasicDBObject();
             System.out.println(status.getId() + "\n");
             System.out.println(status.getUser().getScreenName() + "\n");
             System.out.println(status.getText() + "\n");
             obj.put("tweet_ID", status.getId());
             obj.put("usuario", status.getUser().getScreenName());
             obj.put("tweet", status.getText());
             
             try {
                 collection.insert(obj);
             } catch (Exception e) {
                 System.out.println("Erro de conexão: " + e.getMessage());
             }
         }
    
         @Override
         public void onDeletionNotice(StatusDeletionNotice sdn) {
             throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
         }
    
         @Override
         public void onTrackLimitationNotice(int i) {
             throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
         }
    
         @Override
         public void onScrubGeo(long l, long l1) {
             throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
         }
    
         @Override
         public void onStallWarning(StallWarning sw) {
             throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
         }
    
         @Override
         public void onException(Exception excptn) {
             throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
             
         } 
         
     };
     
     String palavras[] = {"bigcompras"};
     FilterQuery fq = new FilterQuery();
     fq.track(palavras);
     twitterStream.addListener(listener);
     twitterStream.filter(fq);
    

    }

    public void configuraCredenciais() {
    cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey(“XXX”);
    cb.setOAuthConsumerSecret(“XXX”);
    cb.setOAuthAccessToken(“XXX”);
    cb.setOAuthAccessTokenSecret(“XXX”);
    }

    public void conectaMongoDB() {
    try {
    Mongo mongoCli;
    mongoCli = new MongoClient(“127.0.0.1”);
    banco = mongoCli.getDB(“twDB”);
    collection = banco.getCollection(“tweets”);
    BasicDBObject index = new BasicDBObject(“tweet_ID”,1);
    collection.ensureIndex(index, new BasicDBObject(“unique”,true));
    } catch (UnknownHostException | MongoException ex) {
    System.out.println("MongoException: " + ex.getMessage());
    }
    }

    public static void main(String[] args) throws InterruptedException {
    // TODO code application logic {here
    TwitterApp tw = new TwitterApp();
    tw.conectaMongoDB();
    tw.configuraCredenciais();
    tw.capturaTweets();
    }
    }

Alguém sabe como resolver este problema?

Desde já agradeço!

Emmanuel Ruiz