List of usage examples for twitter4j IDs getNextCursor
@Override
long getNextCursor();
From source file:tientx.supercode.myproejectdemov3.preprocessing.Get1stData.java
public static void preCommentLikeData(Date sdate, Date edate) { try {//from w w w . ja va 2 s .com 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 // w w w .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 www . ja va2s .c o 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.friendsandfollowers.GetFollowersIDs.java
License:Apache License
/** * Usage: java twitter4j.examples.friendsandfollowers.GetFollowersIDs [screen name] * * @param args message//from w w w . j a va 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("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/*from w ww. ja v a2s.c om*/ */ 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 ww. j ava2 s. co 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// w w w.j a v a 2s .co 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:TwitterDownload.TwitterHandler.java
public List<User> getUserFollowers(String searchPhrase, int pageSize) throws TwitterException { //todo test rate limit ArrayList<User> listFollowers = new ArrayList<User>(); long cursor = -1; IDs followersIDs; do {//from w w w .ja va 2s .c om followersIDs = twitter.getFollowersIDs(searchPhrase, cursor); long[] ids = followersIDs.getIDs(); while (ids.length > 0) { long[] searchIds = Arrays.copyOfRange(ids, 0, 100); if (ids.length >= 100) ids = Arrays.copyOfRange(ids, 100, ids.length); else ids = new long[0]; ResponseList<User> users = twitter.lookupUsers(searchIds); for (User user : users) { listFollowers.add(user); } } if (followersIDs.hasNext()) cursor = followersIDs.getNextCursor(); else cursor = -1; } while (cursor > 0 && listFollowers.size() < pageSize); return listFollowers; }
From source file:TwitterDownload.TwitterHandler.java
public List<User> getUserFriends(String searchPhrase, int pageSize) throws TwitterException { //todo test rate limit ArrayList<User> listFriends = new ArrayList<User>(); long cursor = -1; IDs friendsIDs; do {/* w w w . j a va 2s . c o m*/ friendsIDs = twitter.getFriendsIDs(searchPhrase, cursor); long[] ids = friendsIDs.getIDs(); while (ids.length > 0) { long[] searchIds = Arrays.copyOfRange(ids, 0, 100); if (ids.length >= 100) ids = Arrays.copyOfRange(ids, 100, ids.length); else ids = new long[0]; ResponseList<User> users = twitter.lookupUsers(searchIds); for (User user : users) { listFriends.add(user); } } if (friendsIDs.hasNext()) cursor = friendsIDs.getNextCursor(); else cursor = -1; } while (cursor > 0 && listFriends.size() < pageSize); return listFriends; }
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 www . j a v a 2s . co 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(); }