Example usage for twitter4j IDs getIDs

List of usage examples for twitter4j IDs getIDs

Introduction

In this page you can find the example usage for twitter4j IDs getIDs.

Prototype

long[] getIDs();

Source Link

Usage

From source file:org.yukung.following2ldr.command.impl.FindFeedUrlCommand.java

License:Apache License

@Override
public void run() throws Throwable {
    // Twitter??//from   ww w.  jav a2 s  . c  o m
    long start = System.currentTimeMillis();
    String consumerKey = config.getProperty(Constants.CONSUMER_KEY);
    String consumerSecret = config.getProperty(Constants.CONSUMER_SECRET);
    String userName = params.get(0);
    Twitter twitter = new TwitterFactory().getInstance();
    twitter.setOAuthConsumer(consumerKey, consumerSecret);
    RequestToken requestToken = twitter.getOAuthRequestToken();
    String authorizationURL = requestToken.getAuthorizationURL();
    System.out.println(":" + authorizationURL);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Please enter the PIN:");
    String pin = br.readLine();
    AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, pin);
    twitter.setOAuthAccessToken(accessToken);
    long cursor = -1L;
    IDs friendIDs;
    List<Long> iDsList = new ArrayList<Long>(5000);
    do {
        friendIDs = twitter.getFriendsIDs(userName, cursor);
        long[] iDs = friendIDs.getIDs();
        for (long iD : iDs) {
            iDsList.add(iD);
        }
        cursor = friendIDs.getNextCursor();
    } while (friendIDs.hasNext());
    List<long[]> list = new ArrayList<long[]>();
    int offset = 0;
    long[] tmp = new long[100];
    for (Long id : iDsList) {
        if (offset < 100) {
            tmp[offset] = id;
            offset++;
        } else {
            list.add(tmp);
            offset = 0;
            tmp = new long[100];
        }
    }
    list.add(tmp);
    List<URL> urlList = new ArrayList<URL>();
    for (long[] array : list) {
        ResponseList<User> lookupUsers = twitter.lookupUsers(array);
        for (User user : lookupUsers) {
            log.info("URL:" + user.getURL());
            urlList.add(user.getURL());
        }
    }
    String path = "C:\\Users\\ikeda_yusuke\\Documents\\sandbox\\java\\data\\" + userName + ".txt";
    FileWriter writer = new FileWriter(path);
    BufferedWriter out = new BufferedWriter(writer);
    //      PrintWriter pw = new PrintWriter(writer);
    for (URL url : urlList) {
        if (url != null) {
            out.write(url.toString() + "\n");
        }
    }
    out.flush();
    out.close();
    long end = System.currentTimeMillis();
    log.info("?:" + (end - start) + " ms");

    // ??IDor??
    // Twitter API??????ID?
    // ?????ID?URL100???
    // ??URL?

}

From source file:tientx.supercode.myproejectdemov3.preprocessing.Get1stData.java

public static void preCommentLikeData(Date sdate, Date edate) {
    try {/*from   w  w  w .  j a v  a 2  s  . co  m*/
        ArrayList<tientx.supercode.myproejectdemov3.model.User> listUser = USER_SERVICE.getAll();
        int l = listUser.size();
        for (int i = 0; i < l; i++) {
            List<Status> statuses = new ArrayList<>();
            //get friend list
            PagableResponseList<User> friendList = GetTwitterAccount.getAllFriend(TWITTER_SERVICE,
                    Long.parseLong(listUser.get(i).getIdUser()));
            int ll;
            if (friendList != null && (ll = friendList.size()) > 0) {
                System.out.println(TAG + "Friend: " + ll);
                for (int j = 0; j < ll; j++) {
                    try {
                        ResponseList<Status> listStatus = TWITTER_SERVICE
                                .getTwUserTimeline(friendList.get(j).getId(), COUNT);
                        int lll;
                        if (listStatus != null && (lll = listStatus.size()) > 0) {
                            System.out.println(TAG + "All timeline: " + lll);
                            for (int k = 0; k < lll; k++) {
                                Date createDate = listStatus.get(k).getCreatedAt();
                                if (createDate.after(sdate) && createDate.before(edate)
                                        && listStatus.get(k).getRetweetCount() > 0) {
                                    IDs iDs;
                                    long cursor = -1;
                                    do {
                                        iDs = TWITTER_SERVICE.getListRetweeterId(listStatus.get(k).getId(),
                                                COUNT, cursor);
                                        if (iDs != null && iDs.getIDs().length > 0
                                                && (Arrays.toString(iDs.getIDs())
                                                        .contains(friendList.get(j).getId() + ",")
                                                        || Arrays.toString(iDs.getIDs())
                                                                .contains(", " + friendList.get(j).getId()))) {
                                            System.out.println(listStatus.get(k).getText());
                                            System.out.println("--------------");
                                            statuses.add(listStatus.get(k));
                                            break;
                                        }
                                        cursor = iDs.getNextCursor();
                                        Thread.sleep(15000);
                                    } while (iDs != null && iDs.getIDs().length > 0);
                                }
                            }
                        }
                    } catch (TwitterException | InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
            System.out.println(TAG + "All comment/like " + (i + 1) + ": " + statuses.size());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:tweetmining.MiningFunctions.java

/**
 * Returns an ArrayList with the names of the followers of a certain person.
 * @param user User where you want to extract list of friends
 * @return ArrayList of strings with friends names.
 * @throws TwitterException //from   w  ww.j a  v a  2 s  .c  o  m
 */
public ArrayList<String> CreateFriendsList(String user) throws TwitterException {
    ArrayList<String> friends = new ArrayList<String>();
    long cursor = -1;
    IDs ids;

    do {
        ids = twitter.getFollowersIDs(user, cursor);
        for (long id : ids.getIDs()) {
            friends.add(twitter.showUser(id).getName());
        }
    } while ((cursor = ids.getNextCursor()) != 0);

    return friends;
}

From source file:tweetmining.MiningFunctions.java

private ArrayList<User> getRawUsers(String user) throws TwitterException {
    ArrayList<User> friends = new ArrayList<User>();
    long cursor = -1;
    IDs ids;

    do {//from  w  w  w. jav a2 s  .  co m
        ids = twitter.getFollowersIDs(user, cursor);
        for (long id : ids.getIDs()) {
            friends.add(twitter.showUser(id));
        }
    } while ((cursor = ids.getNextCursor()) != 0);

    return friends;
}

From source file:twitter4j.examples.block.GetBlockingUsersIDs.java

License:Apache License

/**
 * Usage: java twitter4j.examples.block.GetBlockingUsersIDs
 *
 * @param args message/*ww  w.j a  v  a  2s .com*/
 */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        IDs ids = twitter.getBlocksIDs();
        for (long id : ids.getIDs()) {
            System.out.println(id);
        }
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get blocking user ids: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.friendsandfollowers.GetFollowersIDs.java

License:Apache License

/**
 * Usage: java twitter4j.examples.friendsandfollowers.GetFollowersIDs [screen name]
 *
 * @param args message//from   ww  w. jav a  2 s.c  om
 */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long cursor = -1;
        IDs ids;
        System.out.println("Listing followers's ids.");
        do {
            if (0 < args.length) {
                ids = twitter.getFollowersIDs(args[0], cursor);
            } else {
                ids = twitter.getFollowersIDs(cursor);
            }
            for (long id : ids.getIDs()) {
                System.out.println(id);
            }
        } while ((cursor = ids.getNextCursor()) != 0);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get followers' ids: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.friendsandfollowers.GetFriendsIDs.java

License:Apache License

/**
 * Usage: java twitter4j.examples.friendsandfollowers.GetFriendsIDs [screen name]
 *
 * @param args message//w  ww.j  a  va 2s.co m
 */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long cursor = -1;
        IDs ids;
        System.out.println("Listing following ids.");
        do {
            if (0 < args.length) {
                ids = twitter.getFriendsIDs(args[0], cursor);
            } else {
                ids = twitter.getFriendsIDs(cursor);
            }
            for (long id : ids.getIDs()) {
                System.out.println(id);
            }
        } while ((cursor = ids.getNextCursor()) != 0);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get friends' ids: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.friendship.GetIncomingFriendships.java

License:Apache License

/**
 * Usage: java twitter4j.examples.friendship.GetIncomingFriendships
 *
 * @param args message//from  w w  w .j a  v  a  2  s  .  c  o  m
 */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long cursor = -1;
        IDs ids;
        System.out.println("Showing incoming pending follow request(s).");
        do {
            ids = twitter.getIncomingFriendships(cursor);
            for (long id : ids.getIDs()) {
                System.out.println(id);
            }
        } while ((cursor = ids.getNextCursor()) != 0);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get incoming friendships: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.friendship.GetOutgoingFriendships.java

License:Apache License

/**
 * Usage: java twitter4j.examples.friendship.GetOutgoingFriendships
 *
 * @param args message/*from  w w  w  . j  a  v a  2 s .c  o m*/
 */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long cursor = -1;
        IDs ids;
        System.out.println("Showing outgoing pending follow request(s).");
        do {
            ids = twitter.getOutgoingFriendships(cursor);
            for (long id : ids.getIDs()) {
                System.out.println(id);
            }
        } while ((cursor = ids.getNextCursor()) != 0);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get outgoing friendships: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.mute.GetMutingUsersIDs.java

License:Apache License

/**
  * Usage: java twitter4j.examples.mute.GetMutingUsersIDs
  */*  w  w w  .j  av  a  2s .  co  m*/
  * @param args message
  */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        IDs ids = twitter.getMutesIDs(-1L);
        for (long id : ids.getIDs()) {
            System.out.println(id);
        }
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get muting user ids: " + te.getMessage());
        System.exit(-1);
    }
}