Example usage for twitter4j Twitter showUser

List of usage examples for twitter4j Twitter showUser

Introduction

In this page you can find the example usage for twitter4j Twitter showUser.

Prototype

User showUser(long userId) throws TwitterException;

Source Link

Document

Returns extended information of a given user, specified by ID or screen name as per the required id parameter.

Usage

From source file:twitter4j.examples.list.ShowUserListMembership.java

License:Apache License

/**
 * Usage: java twitter4j.examples.list.ShowUserListMembership [list id] [user id]
 *
 * @param args message// w w w  . jav  a  2  s . co m
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: java twitter4j.examples.list.ShowUserListMembership [list id] [user id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long listId = Long.parseLong(args[0]);
        UserList list = twitter.showUserList(listId);
        long userId = Integer.parseInt(args[1]);
        User user = twitter.showUser(userId);
        try {
            twitter.showUserListMembership(listId, userId);
            System.out.println("@" + user.getScreenName() + " is in the list:" + list.getName());
        } catch (TwitterException te) {
            if (te.getStatusCode() == 404) {
                System.out.println("@" + user.getScreenName() + " is not in the list:" + list.getName());
            }
        }
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to check user membership: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.list.ShowUserListSubscription.java

License:Apache License

/**
 * Usage: java twitter4j.examples.list.ShowUserListSubscription [list id] [user id]
 *
 * @param args message//  w ww  .  j a v a  2  s.c  om
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: java twitter4j.examples.list.ShowUserListSubscription [list id] [user id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long listId = Long.parseLong(args[0]);
        UserList list = twitter.showUserList(listId);
        long userId = Integer.parseInt(args[1]);
        User user = twitter.showUser(userId);
        try {
            twitter.showUserListSubscription(listId, userId);
            System.out.println("@" + user.getScreenName() + " is subscribing the list:" + list.getName());
        } catch (TwitterException te) {
            if (te.getStatusCode() == 404) {
                System.out.println(
                        "@" + user.getScreenName() + " is not subscribing  the list:" + list.getName());
            }
        }
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to check user subscription: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.user.ShowUser.java

License:Apache License

/**
 * Usage: java twitter4j.examples.user.ShowUser [screen name]
 *
 * @param args message/*from   w  w w.j a  va  2 s . c  om*/
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.user.ShowUser [screen name]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        User user = twitter.showUser(args[0]);
        if (user.getStatus() != null) {
            System.out.println("@" + user.getScreenName() + " - " + user.getStatus().getText());
        } else {
            // the user is protected
            System.out.println("@" + user.getScreenName());
        }
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to delete status: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:TwitterLookUpUsers.LookupUsers.java

License:Apache License

public static void main(String[] args) throws InterruptedException {

    Postgresql.DBBaglan();// w ww  .  j a va 2s.  c  o  m
    Postgresql.DBSelect();
    Twitter twitter = new TwitterFactory().getInstance();

    for (int j = 0; j < sonuc.length; j++) {

        try {
            User user = twitter.showUser(sonuc[j]);
            if (user.getStatus() != null) {
                System.out.println((j + 1) + ". Sorgu___________________________________");
                System.out.println("@" + user.getScreenName());
                System.out.println(user.getTimeZone());
                System.out.println("@" + user.getName());
                System.out.println("@" + user.getURL());
                System.out.println("LOKASYONN  : " + user.getLocation());
                System.out.println("@" + user.getDescription());
                System.out.println("@" + user.getOriginalProfileImageURL());
                System.out.println("@" + user.getMiniProfileImageURL());
                System.out.println("@" + user.getProfileBackgroundImageURL());
                System.out.println("_______________________________________________");

                if (lokasyon[j].contains(user.getLocation()))

                {
                    System.out.println("KULLANICI BU OLABLR*************************");

                }
            } else {

                // the user is protected
                System.out.println((j + 1) + ". Sorgu______________________________________");
                System.out.println("@" + user.getScreenName() + "---- KULLANICI PUBLIC DEL");
                System.out.println("___________________________________________________");
            }

        }

        catch (TwitterException te)

        {
            te.printStackTrace();

            if ((te.getErrorCode() == 88)) {
                System.err.println("EXCEED..............");
                Thread.sleep(900000); //wait 15 min
            }
            System.out.println();

        }

    }

    System.exit(0);
}

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  av a2s . 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) {

    /*****//*ww  w  .j  ava2s . c  om*/
    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:twitterrest.Followersids.java

License:Apache License

public static void main(String[] args) throws TwitterException {

    String ScreenName = "anondroid5";//??

    // ?//www  .  j a  v  a 2 s  .  c  om
    Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
            .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();
    Twitter twitter = new TwitterFactory(configuration).getInstance();

    List<Long> followersList = followers(twitter, ScreenName);//?
    System.out.println(ScreenName + ":FolloweID List");
    for (int i = 0; i < followersList.size(); i++) {
        System.out.println("[" + (i + 1) + "]" + followersList.get(i));
        //?
        User user = twitter.showUser(followersList.get(i));
        System.out.println("User ID : " + user.getId());//UserID
        System.out.println("ScreenName : " + user.getScreenName());//ScreenName
        System.out.println("User's Name : " + user.getName());//UserName
        System.out.println("Number of Followers : " + user.getFollowersCount());//Number of Followers
        System.out.println("Number of Friends : " + user.getFriendsCount());//Number of Friends
        System.out.println("Language : " + user.getLang());//Language
    }
}

From source file:ua.group06.presentation.UserLoginTwitter.java

/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request/*w  w  w  .  java 2  s  .  c  o  m*/
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Twitter twitter = twitterauth.getTwitter();
    RequestToken requestToken = twitterauth.getRequestToken();
    //RequestToken requestToken = (RequestToken) request.getSession().getAttribute("requestToken");
    String verifier = request.getParameter("oauth_verifier");
    System.err.println(twitter + " " + requestToken + " " + verifier);
    try {
        AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
        System.err.println(accessToken.getScreenName());
        User twitterUser = twitter.showUser(accessToken.getUserId());
        String fullName = twitterUser.getName();
        String fName = "";
        String lName = "";
        String[] names = fullName.split(" ");
        if (names.length == 1) {
            fName = names[0];
        } else if (names.length >= 2) {
            fName = names[0];
            lName = names[names.length - 1];
        }
        ExternalUser user = userService.authenticateOrCreate(accessToken.getScreenName(), "", fName, lName);

        if (user != null) {
            HttpSession session = request.getSession();
            session.setAttribute("user", user);
        }
        //request.getSession().removeAttribute("requestToken");
    } catch (TwitterException e) {
        throw new ServletException(e);
    }
    response.sendRedirect("homepage");
}

From source file:uk.ac.susx.tag.method51.webapp.handler.TwitterPinAuthHandler.java

License:Apache License

private void getUserInfo(String target, Request baseRequest, HttpServletRequest request,
        HttpServletResponse response) throws IOException {
    final Params params = new Params();
    params.addValidator("id", new SystemStringValidator(true));

    new DoSomethingAfterValidatingMyParams(params, request, response) {
        @Override/*from w w  w  .ja v  a 2  s. co m*/
        public void something() throws IOException {
            final String id = request.getParameter("id");
            final Twitter twitter = newTwitterInstance(ApiKeyStore.getKey(id));

            try {
                final AccountSettings as = twitter.getAccountSettings();
                final String userScreenName = twitter.getScreenName();
                final long userId = twitter.getId();
                final User user = twitter.showUser(userId);

                okHereIsYourJson(response, "name", user.getName(), "description", user.getDescription(),
                        "created", user.getCreatedAt(), "favourites_count", user.getFavouritesCount(),
                        "followers_count", user.getFollowersCount(), "friends_count", user.getFriendsCount(),
                        "profile_image_url", user.getProfileImageURL(), "screen_name", userScreenName,
                        "user_id", userId, "language", as.getLanguage(), "sleep_time_enabled",
                        as.isSleepTimeEnabled(), "sleep_end_time", as.getSleepEndTime(), "sleep_start_time",
                        as.getSleepStartTime(), "timezone", as.getTimeZone(), "trend_locations",
                        as.getTrendLocations(), "always_use_https", as.isAlwaysUseHttps(),
                        "discoverable_by_email", as.isDiscoverableByEmail(), "geo_enabled", as.isGeoEnabled());
            } catch (TwitterException e) {
                LOG.warn("Failed to retrieve users data.", e);
                error(e.getMessage());
            }
        }
    };
}