Example usage for twitter4j.conf ConfigurationBuilder setOAuthAccessToken

List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthAccessToken

Introduction

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

Prototype

public ConfigurationBuilder setOAuthAccessToken(String oAuthAccessToken) 

Source Link

Usage

From source file:twitterlab.TwitterLab.java

/**
 * @param args the command line arguments
 *///from w  w w.ja v a2 s.  c o  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 ava2s .  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  w  w  .  j  ava2  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());

}

From source file:twitterNetwork.extractUser.java

/*****token*/
public void dataextraction(ArrayList userName, int k, int l) {

    /*****///from ww w .  ja  v a  2s .c  o m
    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();

    System.out.println("k" + k + "l" + l);
    int j = k;
    Follower obj = new Follower();
    User user1 = null;
    while (j < userName.size()) {
        try {
            // System.out.println(userName.get(j));
            int name = Integer.parseInt(userName.get(j).toString());
            if (l == 1) {
                user1 = twitter7.showUser(name);
            } else if (l == 2) {
                user1 = twitter2.showUser(name);
            } else if (l == 3) {
                user1 = twitter3.showUser(name);
            } else if (l == 4) {
                user1 = twitter4.showUser(name);
            } else if (l == 5) {
                user1 = twitter5.showUser(name);
            } else if (l == 6) {
                user1 = twitter6.showUser(name);
            } else if (l == 7) {
                user1 = twitter1.showUser(name);

            } else if (l == 8) {
                user1 = twitter8.showUser(name);
            } else {
                l = 1;
                dataextraction(userName, j, l);
            }

            //System.out.println(userName.get(j)+"---"+j);
            if (user1.getRateLimitStatus().getRemaining() > 2) {
                System.out.println(userName.get(j) + "," + user1.getScreenName());
            } else {

                System.out.println("rate2");
                //System.out.println(l+1+"---"+j);
                int m = l + 1;
                if (m == 9) {
                    m = 1;
                }
                dataextraction(userName, j, m);

            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        j++;
    }

}

From source file:twittersentimentanalysis.TwitterSentimentAnalysis.java

private static ConfigurationBuilder getAuthentication() {
    logger.info("getAuthentication()");
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey("******************");
    cb.setOAuthConsumerSecret("******************");
    cb.setOAuthAccessToken("******************");
    cb.setOAuthAccessTokenSecret("******************");
    return cb;//from w  w  w .jav a 2  s.c  o  m
}

From source file:TwitterStats.Facade.Twitter.java

public Twitter() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey("4bUGil5YTghhAZj05wJZX0wjB");
    builder.setOAuthAccessToken("330584281-bFRvETvWXnH7fb9acRMIIagP1oGQeMK0mv4RiIUB");
    builder.setOAuthConsumerSecret("nZPD0wtVuQRmqSdyEnGN4d8TRv63BPlUvkVOAZSZ2O8DfDGwGX");
    builder.setOAuthAccessTokenSecret("FGSC23QvIqBYRKleno9OQI3eBo8J54hZ5btpAf1jR2bYy");
    twitter4j.conf.Configuration configuration = builder.build();
    twitter = (new TwitterFactory(configuration)).getInstance();
}

From source file:uk.co.flax.ukmp.twitter.AbstractTwitterClient.java

License:Apache License

protected Configuration buildConfiguration() throws IOException {
    Map<String, String> authMap = readAuthConfiguration();

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthAccessToken(authMap.get(ACCESS_TOKEN));
    cb.setOAuthAccessTokenSecret(authMap.get(ACCESS_SECRET));
    cb.setOAuthConsumerKey(authMap.get(CONSUMER_KEY));
    cb.setOAuthConsumerSecret(authMap.get(CONSUMER_SECRET));

    return cb.build();
}

From source file:ws.project.languagebasedlexiconanalisys.TwitterStreamAnalizer.java

void parseStream() throws IOException {
    //Inizializza file JSON
    FileWriter file = new FileWriter("data.json");
    JSONObject obj = new JSONObject();
    final JSONArray data = new JSONArray();
    obj.put("data", data);
    file.write(obj.toJSONString());//from   w w  w  .  jav  a 2s. com
    file.flush();
    file.close();

    SimpleDateFormat currentDate = new SimpleDateFormat();
    currentDate.applyPattern("dd-MM-yyyy");
    final String currentDateStr = currentDate.format(new Date());

    ConfigurationBuilder cfg = new ConfigurationBuilder();
    cfg.setOAuthAccessToken("3065669171-9Hp3VZbz7f0BCsvWWFfgywgqimSIp1AlT98745S");
    cfg.setOAuthAccessTokenSecret("AUmg0AdhHzMXisnP1WV7Wnsw5amWFQPyIojI5aBG5qV4A");
    cfg.setOAuthConsumerKey("arieQRhL2WwgRFfXFLAJp5Hkw");
    cfg.setOAuthConsumerSecret("NvmWqgN1UKKPUWoh9d9Z2PuQobOah8IR5faqX2WjDGBL053sWE");

    StatusListener listener;
    listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {
            SimpleDateFormat tweetDate = new SimpleDateFormat();
            tweetDate.applyPattern("dd-MM-yyyy");
            String tweetDateStr = tweetDate.format(status.getCreatedAt());

            try {
                indexer.openWriter(currentDateStr);
            } catch (IOException ex) {
                Logger.getLogger(TwitterStreamAnalizer.class.getName()).log(Level.SEVERE, null, ex);
            }

            //CHIUDO se cambio giorno ma non ho raggiunto l'1%
            if (!tweetDateStr.equals(currentDateStr)) {
                try {
                    indexer.closeWriter();
                } catch (IOException ex) {
                    Logger.getLogger(TwitterStreamAnalizer.class.getName()).log(Level.SEVERE, null, ex);
                }
                writeOnJson(currentDateStr);
                System.out.println("Giorno successivo, completato senza aver raggiunto 1%");
                System.exit(0);
            }
            tot_count++;

            if (status.getLang().equals("it")) {
                it_count++;
                try {
                    indexer.addTweet(id, status.getText());
                } catch (IOException ex) {
                    Logger.getLogger(TwitterStreamAnalizer.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
            try {
                indexer.closeWriter();
            } catch (IOException ex) {
                Logger.getLogger(TwitterStreamAnalizer.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        @Override
        public void onTrackLimitationNotice(int i) {
        }

        @Override
        public void onScrubGeo(long l, long l1) {
        }

        @Override
        public void onStallWarning(StallWarning sw) {
        }

        @Override
        public void onException(Exception excptn) {
            TwitterException exc = (TwitterException) excptn;
            if (exc.exceededRateLimitation()) {
                try {
                    indexer.closeWriter();
                } catch (IOException ex) {
                    Logger.getLogger(TwitterStreamAnalizer.class.getName()).log(Level.SEVERE, null, ex);
                }
                writeOnJson(currentDateStr);
                System.out.println("1% raccolto, dati raccolti. Amen");
            }
        }

    };

    TwitterStream twitterStream = new TwitterStreamFactory(cfg.build()).getInstance();
    twitterStream.addListener(listener);

    indexer.addIndex(currentDateStr);
    indexer.openWriter(currentDateStr);
    twitterStream.sample();

}