Example usage for twitter4j.conf ConfigurationBuilder setOAuthAccessTokenSecret

List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthAccessTokenSecret

Introduction

In this page you can find the example usage for twitter4j.conf ConfigurationBuilder setOAuthAccessTokenSecret.

Prototype

public ConfigurationBuilder setOAuthAccessTokenSecret(String oAuthAccessTokenSecret) 

Source Link

Usage

From source file:twitfeedbot.RespondServlet.java

License:Open Source License

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    ResponseList<Status> mentions;
    Twitter twit;//w w w.j  av  a2 s.  co m
    StringBuilder builder = new StringBuilder();
    long lastPostId = 0;

    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Entity lastPostIdEntity;

    resp.setContentType("text/html");
    resp.getWriter().println("<html>");
    resp.getWriter().println("<body>");
    try {
        ConfigurationBuilder twitterConfigBuilder = new ConfigurationBuilder();
        twitterConfigBuilder.setDebugEnabled(false);

        System.setProperty("WORDNIK_API_KEY", WORDNIK_KEY);
        twitterConfigBuilder.setOAuthConsumerKey(CONSUMER_KEY);
        twitterConfigBuilder.setOAuthConsumerSecret(CONSUMER_SECRET);
        twitterConfigBuilder.setOAuthAccessToken(ACCESS_TOKEN);
        twitterConfigBuilder.setOAuthAccessTokenSecret(ACCESS_SECRET);

        twit = new TwitterFactory(twitterConfigBuilder.build()).getInstance();
        mentions = twit.getMentionsTimeline();

        lastPostIdEntity = datastore.get(KeyFactory.createKey("lastPostIDEntity", "ID"));
        lastPostId = Long.parseLong(lastPostIdEntity.getProperty("lastPostID").toString());

        if (mentions.size() == 0 || mentions.get(0).getId() == lastPostId)
            resp.getWriter().println("No mentions so far...<br>");
        else {
            resp.getWriter().println("Responding to mentions...<br>");
            for (Status mention : mentions) {
                builder.setLength(0); // Clear the String Builder
                if (lastPostId < mention.getId()) {
                    //Figure out how to like a reply with certain words (best fuck etc)
                    if (mention.getUser().getId() == twit.getId())
                        ;//don't respond to myself
                    else if (mention.isRetweeted())
                        ; //don't respond to retweet
                    else if (mention.getText().toLowerCase().contains("bye")) // Say goodbye
                    {
                        builder.setLength(0); // Clear the String Builder 
                        builder.append("@").append(mention.getUser().getScreenName()).append(" Ok. Bye");
                    } else {
                        builder.setLength(0); // Clear the String Builder
                        builder.append("@").append(mention.getUser().getScreenName());
                        builder.append(" ");

                        //Append Wordnik example sentence
                        builder.append(WordApi.topExample(WordsApi.randomWord().getWord()).getText());
                        if (builder.length() > 140) {
                            if (builder.lastIndexOf(";", 110) > 0)
                                builder.setLength(builder.lastIndexOf(";", 110));
                            else if (builder.lastIndexOf(":", 110) > 0)
                                builder.setLength(builder.lastIndexOf(":", 110));
                            else if (builder.lastIndexOf(",", 110) > 0)
                                builder.setLength(builder.lastIndexOf(",", 110));
                            else
                                builder.setLength(110);
                        }
                    }
                    twit.updateStatus(builder.toString());
                    resp.getWriter().println("Reply posted: " + builder.toString() + "<br>");
                    builder.delete(0, builder.length()); //Clear the builder
                }
            }
            //Save last post ID
            lastPostIdEntity.setProperty("lastPostID", (Long.toString(mentions.get(0).getId())));
            datastore.put(lastPostIdEntity);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
        resp.getWriter().println("Input file(s) not found<br>");
        resp.getWriter().println("<pre>");
        e.printStackTrace(resp.getWriter());
        resp.getWriter().println("</pre>");
    } catch (EntityNotFoundException e) {
        resp.getWriter().println("lastPostID not found. Creating...<br>");
        lastPostIdEntity = new Entity("lastPostIDEntity", "ID");
        //lastPostIdEntity.setProperty("lastPostID", 0);
        lastPostIdEntity.setProperty("lastPostID", "883352596160946176");
        datastore.put(lastPostIdEntity);

    } catch (TwitterException e) {
        resp.getWriter().println("Problem with Twitter <br>");
        resp.getWriter().println("<pre>");
        e.printStackTrace(resp.getWriter());
        resp.getWriter().println("</pre>");
    } catch (KnickerException e) {
        e.printStackTrace(System.err);
        resp.getWriter().println("Problem with Wordnik <br>");
        resp.getWriter().println("<pre>");
        e.printStackTrace(resp.getWriter());
        resp.getWriter().println("</pre>");
    } catch (Exception e) {
        e.printStackTrace(System.err);
        resp.getWriter().println("<pre>");
        e.printStackTrace(resp.getWriter());
        resp.getWriter().println("</pre>");
    }
}

From source file:twitfeedbot.UpdateStatusServlet.java

License:Open Source License

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    StringBuilder builder = new StringBuilder(140);
    GetFeed feed = new GetFeed(feedsFile);
    Random r = new Random();

    resp.setContentType("text/plain; charset=UTF-8");

    try {/*from  www.  j  a va 2 s .  c  om*/
        resp.getWriter().println("Updating status...");
        ConfigurationBuilder twitterConfigBuilder = new ConfigurationBuilder();
        twitterConfigBuilder.setDebugEnabled(false);

        System.setProperty("WORDNIK_API_KEY", WORDNIK_KEY);
        twitterConfigBuilder.setOAuthConsumerKey(CONSUMER_KEY);
        twitterConfigBuilder.setOAuthConsumerSecret(CONSUMER_SECRET);
        twitterConfigBuilder.setOAuthAccessToken(ACCESS_TOKEN);
        twitterConfigBuilder.setOAuthAccessTokenSecret(ACCESS_SECRET);

        twit = new TwitterFactory(twitterConfigBuilder.build()).getInstance();

        //Append feed title
        try {
            builder.append(feed.title()).append(separator[(r.nextInt(separator.length))]);
        } catch (FeedException e) {
            resp.getWriter().println("Problem with RSS Feed <br> <pre>");
            e.printStackTrace(resp.getWriter());
        }

        //Append Wordnik example sentence
        builder.append(WordApi.topExample(WordsApi.randomWord().getWord()).getText());
        if (builder.length() > 140) //Tweets are maximum 140 characters
        {
            if (builder.lastIndexOf(";", 110) > 0)
                builder.setLength(builder.lastIndexOf(";", 110));
            else if (builder.lastIndexOf(":", 110) > 0)
                builder.setLength(builder.lastIndexOf(":", 110));
            else if (builder.lastIndexOf(",", 110) > 0)
                builder.setLength(builder.lastIndexOf(",", 110));
            else
                builder.setLength(110);
        }
        //Add a global trend
        builder.append(
                " " + twit.getPlaceTrends(1).getTrends()[r.nextInt(twit.getPlaceTrends(1).getTrends().length)]
                        .getName());
        // Make up a trend by combining two words
        builder.append(" #" + WordsApi.randomWord().getWord() + WordsApi.randomWord().getWord());

        if (builder.length() > 140)
            builder.setLength(140); //Tweets are limited to 140 characters

        twit.updateStatus(builder.toString());
        resp.getWriter().println("Tweet posted: " + builder.toString());
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
        resp.getWriter().println("Input file(s) not found<br>");

        resp.getWriter().println("<pre>");
        e.printStackTrace(resp.getWriter());
        resp.getWriter().println("</pre>");
    } catch (TwitterException e) {
        resp.getWriter().println("Problem with Twitter <br>");
        resp.getWriter().println("<pre>");
        e.printStackTrace(resp.getWriter());
        resp.getWriter().println("</pre>");
    } catch (KnickerException e) {
        e.printStackTrace(System.err);
        resp.getWriter().println("Problem with Wordnik <br>");
        resp.getWriter().println("<pre>");
        e.printStackTrace(resp.getWriter());
        resp.getWriter().println("</pre>");
    } catch (Exception e) {
        e.printStackTrace(System.err);
        resp.getWriter().println("<pre>");
        e.printStackTrace(resp.getWriter());
        resp.getWriter().println("</pre>");
    }
}

From source file:twitter.crawler.TwitterCrawler.java

public static void main(String[] args) {
    try {/* ww w  .j  a v a2  s.  co m*/
        // Authorise the library
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setOAuthConsumerKey("AhoydO8uSe4v8NEq7j2ISGFlq");
        cb.setOAuthConsumerSecret("ptKEYwq3G9vpFkqAhvwFLSWFcBW8U1SfqycECwK4cH6wThVba6");
        cb.setOAuthAccessToken("778240255577194496-taafqDIHebrg972oxT5kTqcNd3Uojod");
        cb.setOAuthAccessTokenSecret("DMRmeRahnLJRvCBIGQGTaTzE6Pr3PAZMgMsfWIT5ue3PD");
        Twitter twitter = new TwitterFactory(cb.build()).getInstance();
        User user = twitter.verifyCredentials(); // Get main user

        long cursor = -1;

        // Print user profile
        System.out.println("@" + user.getScreenName());
        System.out.println(user.getId());
        System.out.println(user.getProfileImageURL());
        System.out.println(user.getFriendsCount() + " friends.");
        System.out.println("-------");

        // Print Home Timeline
        List<Status> statuses = twitter.getHomeTimeline();
        System.out.println("Showing @" + user.getScreenName() + "'s home timeline.");

        for (Status status : statuses) {
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        }

        //Print followers
        System.out.println("-------");
        System.out.println("Showing Follwers:");

        PagableResponseList<User> followers;

        //do
        //{
        followers = twitter.getFollowersList(user.getScreenName(), cursor);

        for (User follower : followers) {
            System.out.println("@" + follower.getScreenName());
        }
        //}
        //while ((cursor = followers.getNextCursor())!=-1);

        //Print follwees

        System.out.println("-------");
        System.out.println("Showing Followees:");

        PagableResponseList<User> followees;

        do {
            followees = twitter.getFriendsList(user.getScreenName(), cursor);

            for (User followee : followees) {
                System.out.println("@" + followee.getScreenName());
            }
        } while ((cursor = followees.getNextCursor()) != -1);
    }

    catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get timeline: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter.metrics.TwitterMetrics.java

/**
 * @param args the command line arguments
 */// www.  jav a2  s. c om
public static void main(String[] args) {

    try {

        /*Parte que guarda en un archivo*/
        // Se crea el libro
        HSSFWorkbook libro = new HSSFWorkbook();

        // Se crea una hoja dentro del libro
        HSSFSheet hoja = libro.createSheet();

        // Se crea una fila dentro de la hoja
        HSSFRow fila = hoja.createRow(0);

        // Se crea una celda dentro de la fila
        HSSFCell celda = fila.createCell(1);

        // Se crea el contenido de la celda y se mete en ella.
        HSSFRichTextString texto = new HSSFRichTextString("Metricas de Twitter");
        celda.setCellValue(texto);
        /************************************/

        /*Conexion con Mongo DB*/
        MongoClient mongoClient = new MongoClient("localhost", 27017);

        DB db = mongoClient.getDB("JavaMongoTwitter");

        DBCollection datos = db.getCollection("Datos");

        /***********************/

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true);

        cb.setOAuthConsumerKey("TobUISZXWUhDda04ZBtFGQ");
        cb.setOAuthConsumerSecret("7xurVN3iP6VDcBfKdFJxVuNsJjExERFYNmQIDgtg");

        cb.setOAuthAccessToken("849956971-GJBiORhLIuWK4i3MJ2YCd4vidh65N1GzPIb6duXk");
        cb.setOAuthAccessTokenSecret("4MJgPS9grxVuKbczrPCdSjNnumhcWs7t7OLy2F4kkpOdu");

        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();

        User u = twitter.showUser("Pringles");

        System.out.println("Nombre: " + u.getName());
        System.out.println("Seguidores: " + u.getFollowersCount());
        System.out.println("Favoritos: " + u.getFavouritesCount());
        System.out.println("Seguidos: " + u.getFriendsCount());
        System.out.println("Ubicacion: " + u.getLocation());
        System.out.println("Descripcin: " + u.getDescription());
        System.out.println("");

        fila = hoja.createRow(1);
        celda = fila.createCell(0);
        celda.setCellValue(new HSSFRichTextString("Nombre:"));
        celda = fila.createCell(1);
        celda.setCellValue(new HSSFRichTextString(u.getName()));

        fila = hoja.createRow(2);
        celda = fila.createCell(0);
        celda.setCellValue(new HSSFRichTextString("Seguidores:"));
        celda = fila.createCell(1);
        celda.setCellValue(new HSSFRichTextString(u.getFollowersCount() + ""));

        fila = hoja.createRow(3);
        celda = fila.createCell(0);
        celda.setCellValue(new HSSFRichTextString("Favoritos:"));
        celda = fila.createCell(1);
        celda.setCellValue(new HSSFRichTextString(u.getFavouritesCount() + ""));

        fila = hoja.createRow(4);
        celda = fila.createCell(0);
        celda.setCellValue(new HSSFRichTextString("Seguidos:"));
        celda = fila.createCell(1);
        celda.setCellValue(new HSSFRichTextString(u.getFriendsCount() + ""));

        fila = hoja.createRow(5);
        celda = fila.createCell(0);
        celda.setCellValue(new HSSFRichTextString("Ubicacin:"));
        celda = fila.createCell(1);
        celda.setCellValue(new HSSFRichTextString(u.getLocation() + ""));

        fila = hoja.createRow(6);
        celda = fila.createCell(0);
        celda.setCellValue(new HSSFRichTextString("Descripcin:"));
        celda = fila.createCell(1);
        celda.setCellValue(new HSSFRichTextString(u.getDescription() + ""));

        fila = hoja.createRow(7);
        celda = fila.createCell(3);
        celda.setCellValue(new HSSFRichTextString("Tweets!!!"));

        fila = hoja.createRow(9);
        celda = fila.createCell(1);
        celda.setCellValue(new HSSFRichTextString("IdTweet"));
        celda = fila.createCell(2);
        celda.setCellValue(new HSSFRichTextString("Cuenta"));
        celda = fila.createCell(3);
        celda.setCellValue(new HSSFRichTextString("Tweet"));
        celda = fila.createCell(4);
        celda.setCellValue(new HSSFRichTextString("Geolocation"));
        celda = fila.createCell(5);
        celda.setCellValue(new HSSFRichTextString("Place"));
        celda = fila.createCell(6);
        celda.setCellValue(new HSSFRichTextString("Retweets"));
        celda = fila.createCell(7);
        celda.setCellValue(new HSSFRichTextString("Favoritos"));

        Paging paging = new Paging(1, 1000);
        ResponseList<Status> s = twitter.getUserTimeline(u.getId(), paging);
        int i = 0;
        int filaNum = 10;
        for (Status st : s) {

            BasicDBObject obj = new BasicDBObject();

            obj.append("idTweet", s.get(i).getId() + "");
            obj.append("Cuenta", u.getName());
            obj.append("Tweet", s.get(i).getText());
            obj.append("Geolocation", s.get(i).getGeoLocation());
            obj.append("Place", s.get(i).getPlace());
            obj.append("Reteews", s.get(i).getRetweetCount());
            obj.append("Favoritos", s.get(i).getFavoriteCount());

            fila = hoja.createRow(filaNum);
            celda = fila.createCell(1);
            celda.setCellValue(new HSSFRichTextString(s.get(i).getId() + ""));
            celda = fila.createCell(2);
            celda.setCellValue(new HSSFRichTextString(u.getName()));
            celda = fila.createCell(3);
            celda.setCellValue(new HSSFRichTextString(s.get(i).getText()));
            celda = fila.createCell(4);
            celda.setCellValue(new HSSFRichTextString(s.get(i).getGeoLocation() + ""));
            celda = fila.createCell(5);
            celda.setCellValue(new HSSFRichTextString(s.get(i).getPlace() + ""));
            celda = fila.createCell(6);
            celda.setCellValue(new HSSFRichTextString(s.get(i).getRetweetCount() + ""));
            celda = fila.createCell(7);
            celda.setCellValue(new HSSFRichTextString(s.get(i).getFavoriteCount() + ""));

            i++;
            filaNum++;

            datos.insert(obj);
        }

        FileOutputStream elFichero = new FileOutputStream("Metricas_Twitter.xls");
        libro.write(elFichero);
        elFichero.close();

        /********************************/

        System.out.println(i);

        //User usuario = twitter.showUser("@aaron21007");
        //    List<Status> statuses = twitter.getHomeTimeline();
        //    System.out.println("Showing home timeline.");
        //    for (Status status : statuses) {
        //        System.out.println(status.getUser().getName() + ":" +
        //                           status.getText());
        //    }

        //        Twitter unauthenticatedTwitter = new TwitterFactory(cb.build()).getInstance();
        //        
        //          List<String> listaTweets = new ArrayList();
        //          List<Long> ListaRettewts = new ArrayList();
        //          List<Integer> ListaFavoritos = new ArrayList();
        //          List<Integer> ListaMenciones = new ArrayList();
        //          List<Date> ListaFecha = new ArrayList();
        //          List<Long> ListaIds = new ArrayList();
        ////
        //          User usuario = unauthenticatedTwitter.showUser("@aaron21007");
        //          List<Status> ret = unauthenticatedTwitter.getRetweetsOfMe();
        //          List<Status> favoritos = unauthenticatedTwitter.getFavorites();
        //          Paging paging = new Paging(1, 1000);
        //          ResponseList<Status> statuses = unauthenticatedTwitter.getUserTimeline(usuario.getId(), paging);
        //          
        //          
        //          for (Status sta : statuses) {
        //              
        //            ListaIds.add(Long.valueOf(sta.getId()));
        //            listaTweets.add(sta.getText());
        //            ListaRettewts.add(Long.valueOf(Long.parseLong(sta.getRetweetCount() + "")));
        //            ListaMenciones.add(Integer.valueOf(sta.getUserMentionEntities().length));
        //            ListaFecha.add(sta.getCreatedAt());
        //            ListaFavoritos.add(Integer.valueOf(sta.getFavoriteCount()));
        //              System.out.println(sta.getText());
        //              
        //          }
        //          
        //          
        //        
        //       
        //        
    } catch (Exception e) {
        System.err.println("Fallo................." + e);
    }
}

From source file:TwitterAnalytics.TwitterAPI.java

private TwitterAPI() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(consumerKey);
    builder.setOAuthConsumerSecret(consumeSecretKey);
    builder.setOAuthAccessToken(accessToken);
    builder.setOAuthAccessTokenSecret(accessSecretToken);
    Configuration configuration = builder.build();

    TwitterFactory factory = new TwitterFactory(configuration);

    twitter = factory.getInstance();//from   www.j a  v a2s  .c  o m
}

From source file:twitterAPI.Twitter_testing.java

private void connectTwitter() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(OAuthConsumerKey);
    cb.setOAuthConsumerSecret(OAuthConsumerSecret);
    cb.setOAuthAccessToken(AccessToken);
    cb.setOAuthAccessTokenSecret(AccessTokenSecret);
    twitterFactory = new TwitterFactory(cb.build());
    twitter = twitterFactory.getInstance();
    System.out.println("connected");
}

From source file:twitterlab.TwitterLab.java

/**
 * @param args the command line arguments
 *//*  w w w . ja  va 2  s  . co m*/
public static void main(String[] args) {
    // TODO code application logic here
    Users = new ArrayList();

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey("yBSAPlE6wiAQU6CyIiXHSapwN");
    cb.setOAuthConsumerSecret("3CjbEkYyIZvNZ07KYpC55v9vpqxoNmMs1IkC48Wqr5tKXjUnZk");
    cb.setOAuthAccessToken("858371720-0RASIMJeaMbWr2YPmCPyh5OgCP6Kesgz0WvdsLz7");
    cb.setOAuthAccessTokenSecret("cfi5JDGLTUOKHNj7yFIdivg0Hr1bCml3VlQXj5XCOyoFr");

    try {
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter tw = tf.getInstance();
        IDs ids = tw.getFriendsIDs(-1);
        long[] ID;
        if (ids.getIDs().length > 10) {
            ID = new long[10];
            System.arraycopy(ids.getIDs(), 0, ID, 0, 10);
        } else {
            ID = ids.getIDs();
        }
        ResponseList<User> Friends = tw.lookupUsers(ID);
        User[] A = new User[10];
        if (Friends.toArray().length > 0) {
            Users.add(new ArrayList(Arrays.asList(Friends.toArray(A))));
        }
        for (int i = 0; i < ID.length; i++) {
            IDs idsFriend = tw.getFriendsIDs(ID[i], -1);
            long[] IDfriend;
            if (idsFriend.getIDs().length > 10) {
                IDfriend = new long[10];
                System.arraycopy(idsFriend.getIDs(), 0, IDfriend, 0, 10);
            } else {
                IDfriend = idsFriend.getIDs();
            }
            ResponseList<User> FriendsFriend = tw.lookupUsers(IDfriend);
            A = new User[10];
            if (FriendsFriend.toArray().length > 0) {
                Users.add(new ArrayList(Arrays.asList(FriendsFriend.toArray(A))));
            }
            //System.out.println("Sleep?");
            TimeUnit.SECONDS.sleep(60);
        }

        for (int i = 0; i < Users.size(); i++) {
            for (int j = 0; j < Users.get(0).size(); j++) {
                System.out.println(Users.get(i).get(j).getScreenName());
            }
        }

    } catch (Exception e) {
        // Thread.currentThread().interrupt();
        e.printStackTrace();
    }

}

From source file:twittermongodbapp.TwitterMongoDBApp.java

/**
 * @param args the command line arguments
 * @throws twitter4j.TwitterException//  ww  w  . j  a v a 2 s . c  o m
 */
public static void init(ConfigurationBuilder cf) {
    cf.setDebugEnabled(true);
    cf.setJSONStoreEnabled(true);
    cf.setOAuthConsumerKey("SkmxKecZHTxfKmGcQLh7tTufm");
    cf.setOAuthConsumerSecret("HPWFJ6jVrVvuCQd4qT1C0b9q3QqifU27mbcuW3M6f8f81IGGQn");
    cf.setOAuthAccessToken("719105233322905600-FTnAnBZBFZ4AADDTpNyJNPNidsVNvvv");
    cf.setOAuthAccessTokenSecret("D6yIzAKqBLrGLAdIsXk5XvdUehudkgUqO5S7xrWcYp5pu");
}

From source file:twitterNetwork.Follower.java

public void getDetails(String id) throws Exception {
    ConfigurationBuilder cb1 = new ConfigurationBuilder();
    cb1.setOAuthConsumerKey(consumerKey1);
    cb1.setOAuthConsumerSecret(consumerSecret1);
    cb1.setOAuthAccessToken(twitterToken1);
    cb1.setOAuthAccessTokenSecret(twitterSecret1);
    ConfigurationBuilder cb2 = new ConfigurationBuilder();
    cb2.setOAuthConsumerKey(consumerKey2);
    cb2.setOAuthConsumerSecret(consumerSecret2);
    cb2.setOAuthAccessToken(twitterToken2);
    cb2.setOAuthAccessTokenSecret(twitterSecret2);
    ConfigurationBuilder cb3 = new ConfigurationBuilder();
    cb3.setOAuthConsumerKey(consumerKey3);
    cb3.setOAuthConsumerSecret(consumerSecret3);
    cb3.setOAuthAccessToken(twitterToken3);
    cb3.setOAuthAccessTokenSecret(twitterSecret3);

    Twitter twitter1 = new TwitterFactory(cb1.build()).getInstance();
    Twitter twitter2 = new TwitterFactory(cb2.build()).getInstance();
    Twitter twitter3 = new TwitterFactory(cb3.build()).getInstance();

    ConfigurationBuilder cb4 = new ConfigurationBuilder();
    cb4.setOAuthConsumerKey(consumerKey4);
    cb4.setOAuthConsumerSecret(consumerSecret4);
    cb4.setOAuthAccessToken(twitterToken4);
    cb4.setOAuthAccessTokenSecret(twitterSecret4);
    ConfigurationBuilder cb5 = new ConfigurationBuilder();
    cb5.setOAuthConsumerKey(consumerKey5);
    cb5.setOAuthConsumerSecret(consumerSecret5);
    cb5.setOAuthAccessToken(twitterToken5);
    cb5.setOAuthAccessTokenSecret(twitterSecret5);
    ConfigurationBuilder cb6 = new ConfigurationBuilder();
    cb6.setOAuthConsumerKey(consumerKey6);
    cb6.setOAuthConsumerSecret(consumerSecret6);
    cb6.setOAuthAccessToken(twitterToken6);
    cb6.setOAuthAccessTokenSecret(twitterSecret6);
    ConfigurationBuilder cb7 = new ConfigurationBuilder();
    cb7.setOAuthConsumerKey(consumerKey7);
    cb7.setOAuthConsumerSecret(consumerSecret7);
    cb7.setOAuthAccessToken(twitterToken7);
    cb7.setOAuthAccessTokenSecret(twitterSecret7);
    ConfigurationBuilder cb8 = new ConfigurationBuilder();
    cb8.setOAuthConsumerKey(consumerKey8);
    cb8.setOAuthConsumerSecret(consumerSecret8);
    cb8.setOAuthAccessToken(twitterToken8);
    cb8.setOAuthAccessTokenSecret(twitterSecret8);

    Twitter twitter4 = new TwitterFactory(cb4.build()).getInstance();
    Twitter twitter5 = new TwitterFactory(cb5.build()).getInstance();
    Twitter twitter6 = new TwitterFactory(cb6.build()).getInstance();

    Twitter twitter7 = new TwitterFactory(cb7.build()).getInstance();
    Twitter twitter8 = new TwitterFactory(cb8.build()).getInstance();
    setTname(id);/*from   w ww  .  j  a v  a2  s. c  o m*/
    String twittername = this.tname;
    System.out.println(twittername);

    //User u=twitter.showUser(usr);
    //PrintStream out=new PrintStream(new FileOutputStream("F:\\Projects\\Twitter_Network\\out.txt"));
    int w1 = 1, w2 = 1, w3 = 1, w4 = 1, w5 = 1, w6 = 1, w7 = 1, w8 = 1;
    //long id=u.getId();
    long lCursor = -1, nextCursor = -1;
    do {
        String twitterScreenName = twitter1.getScreenName();
        IDs followersIDs = twitter1.getFollowersIDs(twitterScreenName, -1);
        lCursor = nextCursor;
        //out.println("###"+nextCursor);

        //label:

        if (w1 != 16) {

            try {
                followersIDs = twitter1.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter1.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter1.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter1.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
                  out.println(k);
                          
               }*/
            nextCursor = followersIDs.getNextCursor();
            w1++;
        } else if (w2 != 16) {
            try {
                followersIDs = twitter2.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter2.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter2.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter2.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w2++;
        } else if (w3 != 16) {
            //IDs followerIDs = twitter3.getFollowersIDs(twitterScreenName, -1);
            try {
                followersIDs = twitter3.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter3.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter3.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter3.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w3++;
        } else if (w4 != 16) {
            //IDs followerIDs = twitter4.getFollowersIDs(twitterScreenName, -1);
            try {
                followersIDs = twitter4.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter4.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter4.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter4.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w4++;
        } else if (w5 != 16) {
            //IDs followerIDs = twitter5.getFollowersIDs(twitterScreenName, -1);
            try {
                followersIDs = twitter5.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter5.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter5.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter5.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w5++;
        } else if (w6 != 16) {
            //IDs followerIDs = twitter6.getFollowersIDs(twitterScreenName, -1);
            try {
                followersIDs = twitter6.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter6.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter6.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter6.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w6++;
        } else if (w7 != 16) {
            //IDs followerIDs = twitter7.getFollowersIDs(twitterScreenName, -1);
            try {
                followersIDs = twitter7.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter7.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter7.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter7.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w7++;
        } else if (w8 != 16) {
            //IDs followerIDs = twitter8.getFollowersIDs(twitterScreenName, -1);
            try {
                followersIDs = twitter8.getFollowersIDs(twitterScreenName, lCursor);
                long[] ids = followersIDs.getIDs();
                String usr = twittername;
                long[] fofIDs;
                User user = twitter8.showUser(usr);
                String userScreenName = user.getScreenName();
                IDs followerIDsOfFollowers = twitter8.getFollowersIDs(user.getScreenName(), -1);
                long[] arrl = fofIDs = followerIDsOfFollowers.getIDs();
                int n = arrl.length;
                int n2 = 0;
                while (n2 < n) {
                    long subId = arrl[n2];
                    User user1 = twitter8.showUser(subId);
                    if (user1.getStatusesCount() > 200 && user1.getStatusesCount() < 3200) {
                        this.ar.add(user1.getScreenName());
                        this.arpic.add(user1.getMiniProfileImageURL());
                    }
                    ++n2;
                    //TimeUnit.MINUTES.sleep(16);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            /*for(long k: followersIDs.getIDs()){
               //User p=twitter.showUser(k);
             out.println(k);
                     
               }*/
            nextCursor = followersIDs.getNextCursor();
            w8++;

            /*if(twitter8.getRateLimitStatus()!=null){
               if (twitter8.getRateLimitStatus().get("/users/lookup") != null){
               //   break label; 
               }
            }*/
        } else {
            try {
                TimeUnit.MINUTES.sleep(16);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            w1 = 1;
            w2 = 1;
            w3 = 1;
            w4 = 1;
            w5 = 1;
            w6 = 1;
            w7 = 1;
            w8 = 1;
        }

    } while (nextCursor != 0);

    //out.flush();
    //out.close();

}

From source file:twitterNetwork.twitteridextraction.java

public static void main(String args[]) throws TwitterException {
    ConfigurationBuilder cb1 = new ConfigurationBuilder();
    cb1.setOAuthConsumerKey(consumerKey2);
    cb1.setOAuthConsumerSecret(consumerSecret2);
    cb1.setOAuthAccessToken(twitterToken2);
    cb1.setOAuthAccessTokenSecret(twitterSecret2);

    Twitter twitter = new TwitterFactory(cb1.build()).getInstance();
    User user = twitter.showUser(5108161);
    System.out.println(user.getName());
    System.out.println("<h3>Displaying user id of user " + user.getScreenName() + "</h3><br/>");
    System.out.println(user.getId());

}