List of usage examples for twitter4j Twitter getFollowersList
PagableResponseList<User> getFollowersList(long userId, long cursor) throws TwitterException;
From source file:com.amandine.twitterpostforcoucou.Tweet.java
public void getFollowers(String username) { Twitter twitterHandle = this.getTwitter(); long cursor = -1; PagableResponseList<User> followers = null; //do {/*from www . jav a2s . c o m*/ try { followers = twitterHandle.getFollowersList(URLEncoder.encode(username, "UTF-8"), cursor); } catch (TwitterException ex) { //ex.printStackTrace(); logger.log(Level.SEVERE, "Cannot get followers", ex.getMessage()); return; } catch (UnsupportedEncodingException ex) { Logger.getLogger(Tweet.class.getName()).log(Level.SEVERE, null, ex); } for (User follower : followers) { // TODO: Collect top 10 followers here System.out.println(follower.getName() + " has " + follower.getFollowersCount() + " follower(s)"); } //} while ((cursor = followers.getNextCursor()) != 0); }
From source file:com.klinker.android.twitter.ui.profile_viewer.fragments.ProfileFragment.java
License:Apache License
public void getFollowers(final User user, final AsyncListView listView) { spinner.setVisibility(View.VISIBLE); canRefresh = false;//from w w w . ja v a 2 s .c o m new Thread(new Runnable() { @Override public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); try { if (followingIds == null && user.getId() == settings.myId) { long currCursor = -1; IDs idObject; int rep = 0; do { // gets 5000 ids at a time idObject = twitter.getFriendsIDs(settings.myId, currCursor); long[] lIds = idObject.getIDs(); followingIds = new ArrayList<Long>(); for (int i = 0; i < lIds.length; i++) { followingIds.add(lIds[i]); } rep++; } while ((currCursor = idObject.getNextCursor()) != 0 && rep < 3); } } catch (Throwable t) { followingIds = null; } PagableResponseList<User> friendsPaging = twitter.getFollowersList(user.getId(), currentFollowers); for (int i = 0; i < friendsPaging.size(); i++) { followers.add(friendsPaging.get(i)); } if (friendsPaging.size() > 17) { hasMore = true; } else { hasMore = false; } currentFollowers = friendsPaging.getNextCursor(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { if (followersAdapter == null) { if (followingIds == null) { // we will do a normal array adapter followersAdapter = new PeopleArrayAdapter(context, followers); } else { followersAdapter = new FollowersArrayAdapter(context, followers, followingIds); } listView.setAdapter(followersAdapter); } else { followersAdapter.notifyDataSetChanged(); } if (settings.roundContactImages) { ImageUtils.loadSizedCircleImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache, 96); } else { ImageUtils.loadImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache); } String url = user.getProfileBannerURL(); ImageUtils.loadImage(context, background, url, mCache); canRefresh = true; spinner.setVisibility(View.GONE); } }); } catch (Exception e) { e.printStackTrace(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { if (user != null && user.isProtected()) { Toast.makeText(context, getResources().getString(R.string.protected_account), Toast.LENGTH_SHORT).show(); if (settings.roundContactImages) { ImageUtils.loadSizedCircleImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache, 96); } else { ImageUtils.loadImage(context, profilePicture, user.getOriginalProfileImageURL(), mCache); } String url = user.getProfileBannerURL(); ImageUtils.loadImage(context, background, url, mCache); } else { Toast.makeText(context, getResources().getString(R.string.error_loading_timeline), Toast.LENGTH_SHORT).show(); } spinner.setVisibility(View.GONE); canRefresh = false; hasMore = false; } }); } } }).start(); }
From source file:de.vanita5.twittnuker.loader.support.UserFollowersLoader.java
License:Open Source License
@Override protected PagableResponseList<User> getCursoredUsers(final Twitter twitter, final CursorPaging paging) throws TwitterException { if (twitter == null) return null; if (mUserId > 0) return twitter.getFollowersList(mUserId, paging); else if (mScreenName != null) return twitter.getFollowersList(mScreenName, paging); return null;//ww w . j av a 2 s.c o m }
From source file:org.getlantern.firetweet.loader.support.UserFollowersLoader.java
License:Open Source License
@Override protected PageableResponseList<User> getCursoredUsers(final Twitter twitter, final CursorPaging paging) throws TwitterException { if (twitter == null) return null; if (mUserId > 0) return twitter.getFollowersList(mUserId, paging); else if (mScreenName != null) return twitter.getFollowersList(mScreenName, paging); return null;//from w ww .ja v a2 s. c o m }
From source file:org.wso2.carbon.connector.twitter.TwitterGetFollowers.java
License:Open Source License
@Override public void connect(MessageContext messageContext) throws ConnectException { if (log.isDebugEnabled()) { log.info("executing twitter get user time line"); }/*from www.j ava 2 s .com*/ try { String screenName = (TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME) != null && !TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME) : null; String userID = (TwitterUtils.lookupTemplateParamater(messageContext, USER_ID) != null && !TwitterUtils.lookupTemplateParamater(messageContext, USER_ID).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, USER_ID) : null; String count = (TwitterUtils.lookupTemplateParamater(messageContext, COUNT) != null && !TwitterUtils.lookupTemplateParamater(messageContext, COUNT).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, COUNT) : null; Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); List<User> results = null; if (screenName != null && !screenName.isEmpty()) { if (count != null && !count.isEmpty()) { results = twitter.getFollowersList(screenName, Long.parseLong(count)); } else { results = twitter.getFollowersList(screenName, -1); } } else if (userID != null && !userID.isEmpty()) { if (count != null && !count.isEmpty()) { results = twitter.getFollowersList(Long.parseLong(userID), Long.parseLong(count)); } else { results = twitter.getFollowersList(Long.parseLong(userID), -1); } } if (log.isDebugEnabled()) { log.error("Retrived results : " + results.toString()); } OMElement element = this.performSearchMessages(results); super.preparePayload(messageContext, element); } catch (TwitterException te) { log.error("Failed to search twitter : " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } catch (Exception te) { log.error("Failed to search generic: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:peoplesearch.FindFriendsAndFollowers.java
public void GetFollowersIDs() { try {// w ww. j av a 2 s .co m // I need to pass the Person name and the TwitterID. //String targetname="Philip Bergkvist"; Twitter twitter = new TwitterFactory().getInstance(); long cursor = -1; IDs ids; ResponseList<User> users1 = null; ResponseList<User> users2 = null; System.out.println("Listing followers's ids."); GraphManager mgr = EmbeddedGraphManager.getInstance(); mgr.init(new File("/usr/local/Cellar/neo4j/2.1.7/libexec/data/forlang1.db")); //mgr.addTwitterAccount(new TwitterAccountImpl(new Date(), "I am Studying", 13, 82, true,"Aalborg", "Philiptwoshoes", 2730631792L)); List<TwitterAccount> twitteraccountslist; twitteraccountslist = null; twitteraccountslist = mgr.listTwitterAccounts(); System.out.println("the number of twitter account in the neo4J DB is" + twitteraccountslist.size()); for (TwitterAccount Twit : twitteraccountslist) { do { TwitterLimitWait tlw = new TwitterLimitWait(); tlw.CheckLimit(); if (0 < twitteraccountslist.size()) { ids = twitter.getFollowersIDs(Twit.getScreenName(), cursor); //.getFollowersIDs(pep[0], cursor); //ids = twitter.getFollowersIDs("Philiptwoshoes", cursor); //.getFollowersIDs(pep[0], cursor); tlw.CheckLimit(); users1 = twitter.getFollowersList(Twit.getScreenName(), cursor); tlw.CheckLimit(); users2 = twitter.getFriendsList(Twit.getScreenName(), cursor); } else { tlw.CheckLimit(); ids = twitter.getFollowersIDs(cursor); } for (User user : users1) { tlw.CheckLimit(); System.out.println("the follower called " + user.getName() + " with twitter handler " + user.getScreenName()); String username = user.getName(); //mgr.addPerson(new PersonImpl(username)); Date Creation = user.getCreatedAt(); tlw.CheckLimit(); String descript = user.getDescription(); boolean empty1 = user.getDescription().isEmpty(); if (empty1 == true) { descript = " "; } tlw.CheckLimit(); int followers = user.getFollowersCount(); tlw.CheckLimit(); int following = user.getFriendsCount(); boolean geo = user.isGeoEnabled(); String loc = user.getLocation(); boolean empty2 = user.getLocation().isEmpty(); if (empty2 == true) { loc = " "; } String screenname = user.getScreenName(); boolean empty3 = user.getScreenName().isEmpty(); if (empty3 == true) { screenname = " "; } tlw.CheckLimit(); long twitID = user.getId(); mgr.linkPersonToTwitterAccount(new PersonImpl(username), new TwitterAccountImpl(Creation, descript, followers, following, geo, loc, screenname, twitID)); mgr.linkTwitterAccounts(new TwitterAccountImpl(Creation, descript, followers, following, geo, loc, screenname, twitID), Twit); } System.out.println("The total number of followers is: " + users1.size()); // the same procedure for the Following for (User user : users2) { tlw.CheckLimit(); System.out.println("the following called " + user.getName() + " with twitter handler " + user.getScreenName()); String username1 = user.getName(); //mgr.addPerson(new PersonImpl(username1)); Date Creation = user.getCreatedAt(); String descript = user.getDescription(); boolean empty1 = user.getDescription().isEmpty(); if (empty1 == true) { descript = " "; } int followers = user.getFollowersCount(); int following = user.getFriendsCount(); boolean geo = user.isGeoEnabled(); String loc = user.getLocation(); boolean empty2 = user.getLocation().isEmpty(); if (empty2 == true) { loc = " "; } String screenname = user.getScreenName(); tlw.CheckLimit(); boolean empty3 = user.getScreenName().isEmpty(); if (empty3 == true) { screenname = " "; } tlw.CheckLimit(); long twitID = user.getId(); //mgr.addTwitterAccount(new TwitterAccountImpl(Creation,descript,followers,following,geo,loc,screenname,twitID)); mgr.linkPersonToTwitterAccount(new PersonImpl(username1), new TwitterAccountImpl(Creation, descript, followers, following, geo, loc, screenname, twitID)); mgr.linkTwitterAccounts(Twit, new TwitterAccountImpl(Creation, descript, followers, following, geo, loc, screenname, twitID)); } System.out.println("The total number of friend is: " + users2.size()); //} } while ((cursor = ids.getNextCursor()) != 0); } mgr.destroy(); // I have to check that the second iteration works fine, because i could not test that. System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get followers' ids: " + te.getMessage()); System.exit(-1); } }
From source file:the_vaps_project.The_vaps_project.java
public static void main(String[] args)/* throws TwitterException */ { // TODO code application logic here /*/*w ww.ja v a2 s . c o m*/ List<Status> status = twitter.getHomeTimeline(); for(Status st : status){ System.out.println(st.getUser().getName()+"--------"+st.getText()); System.out.println(st.getCreatedAt()); }*/ // The factory instance is re-useable and thread safe. /*Twitter twitter2 = tf.getSingleton(); Query query = new Query("source:twitter4j yusukey"); QueryResult result = twitter.search(query); for (Status statuss : result.getTweets()) { System.out.println("@" + statuss.getUser().getName() + ":" + statuss.getText()); }*/ TwitterCriteria criteria = null; Tweet t = null; criteria = TwitterCriteria.create() .setMaxTweets(10).setUntil("2016-11-08").setQuerySearch("#NeverTrump"); /*Scribe s = new Scribe(); s.detruireFichier("tweets.xml"); s.ouvrir("tweets.xml"); s.ecrire("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); s.ecrire("<tweets>\n"); for (int i = 0; i < TweetManager.getTweets(criteria).size(); i++) { t = TweetManager.getTweets(criteria).get(i); s.ecrire("\t<tweet>\n"); s.ecrire("\t\t<text><![CDATA["+t.getText()+"]]></text>\n"); s.ecrire("\t\t<hashtags>"+t.getHashtags()+"</hashtags>\n"); s.ecrire("\t\t<date>"+t.getDate()+"</date>\n"); s.ecrire("\t\t<username>"+t.getUsername()+"</username>\n"); s.ecrire("\t\t<retweets>"+t.getRetweets()+"</retweets>\n"); s.ecrire("\t\t<favorites>"+t.getFavorites()+"</favorites>\n"); s.ecrire("\t\t<id>"+t.getId()+"</id>\n"); s.ecrire("\t\t<geo>"+t.getGeo()+"</geo>\n"); s.ecrire("\t\t<mentions>"+t.getMentions()+"</mentions>\n"); s.ecrire("\t\t<permalink>"+t.getPermalink()+"</permalink>\n"); s.ecrire("\t\t<smileys>"+t.getSmileys()+"</smileys>\n"); s.ecrire("\t\t<polarite>"+t.getPolarite()+"</polarite>\n"); s.ecrire("\t</tweet>\n"); corpus.ecrire(s.filtrerTexte(t.getText() + "\n")); } s.ecrire("</tweets>"); s.fermer();*/ /* SUPER SITE D'EXEMPLES https://github.com/yusuke/twitter4j/tree/master/twitter4j-examples/src/main/java/twitter4j/examples*/ /*PARTIE GRAPHE DES RETWEETS*/ Set<String> nameOfUsers = new HashSet<>(); for (int i = 0; i < TweetManager.getTweets(criteria).size(); i++) { t = TweetManager.getTweets(criteria).get(i); System.out.println(t.getUsername()); nameOfUsers.add(t.getUsername()); } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("gVaO166IGfSCun5Esj1sZ5bX3") .setOAuthConsumerSecret("KhN1L4pXCG5U6d6tee1IGUnIV1bqxieQJDxE2HOx3AGI5npQRE") .setOAuthAccessToken("822018210178469888-4Pr1KRE2rmFvof0O5IUdTlxtkGKamU4") .setOAuthAccessTokenSecret("D1thDl7k8v2s1SupU5ZGhK3U7Mphb69fpUW4JuDou5O65"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter4j.Twitter twitter = tf.getInstance(); /*String[] screenNames = nameOfUsers.toArray(new String[0]); ResponseList<User> usersNames; long cursor = -1; IDs ids; try { usersNames = twitter.lookupUsers(screenNames); for(User u: usersNames){ System.out.println(u.getId()+" "+u.getName()+" "+u.getName()); ids = twitter.getFollowersIDs("username", cursor); twitter.getFollowers } } catch (TwitterException ex) { Exceptions.printStackTrace(ex); }*/ Set<DuoKey> utilisateurs = new HashSet<>(); Set<DuoKey> liens = new HashSet<>(); //User us; try { int nbpages = 0; long cursor = -1; PagableResponseList<User> listeFollowersTemp; ArrayList<User> listeFollowers = new ArrayList<User>(); for (String s : nameOfUsers) { if (!utilisateurs.contains(new DuoKey(s, "auteurTweet"))) { utilisateurs.add(new DuoKey(s, "auteurTweet")); //listeFollowersTemp = twitter.getFollowersList(s, -1); do { TimeUnit.MINUTES.sleep(1); listeFollowersTemp = twitter.getFollowersList(s, cursor); for (User u : listeFollowersTemp) { listeFollowers.add(u); } nbpages++; } while (((cursor = listeFollowersTemp.getNextCursor()) != 0) && nbpages <= 9); //4=100 followers par auteur de tweet recherch } System.out.println(s + ", mes followers sont :"); for (User u : listeFollowers) { utilisateurs.add(new DuoKey(u.getName(), "auteurTweet")); liens.add(new DuoKey(u.getName(), s)); System.out.println("\t" + u.getName()); } listeFollowers.clear(); nbpages = 0; } } catch (TwitterException | InterruptedException ex) { Exceptions.printStackTrace(ex); } Scribe sc = new Scribe(); sc.detruireFichier("graphFollowers.gexf"); sc.ouvrir("graphFollowers.gexf"); sc.ecrire("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); sc.ecrire( "<gexf xmlns=\"http://www.gexf.net/1.2draft/gexf.xsd\" version=\"1.2\" xmlns:viz=\"http://www.gexf.net/1.1draft/viz\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd\">\n"); sc.ecrire("\t<meta lastmodifieddate=\"2017-02-17\">\n"); sc.ecrire("\t\t<creator>Pirboss</creator>\n"); sc.ecrire("\t\t<description>Test v2</description>\n"); sc.ecrire("\t</meta>\n"); sc.ecrire("\t<graph defaultedgetype=\"directed\" mode=\"static\">\n"); sc.ecrire("\t\t<nodes>\n"); ArrayList<DuoKey> distinctListOfUsers = new ArrayList(utilisateurs); System.out.println(distinctListOfUsers.size()); for (int i = 0; i < distinctListOfUsers.size(); i++) { sc.ecrire("\t\t\t<node id=\"" + distinctListOfUsers.get(i).getX().replace("&", "&") + "\" label=\"" + distinctListOfUsers.get(i).getX().replace("&", "&") + "\"/>\n"); } sc.ecrire("\t\t</nodes>\n"); sc.ecrire("\t\t<edges>\n"); ArrayList<DuoKey> distinctListOfLinks = new ArrayList(liens); System.out.println(distinctListOfLinks.size()); for (int i = 0; i < liens.size(); i++) { sc.ecrire("\t\t\t<edge id=\"" + i + "\" source=\"" + distinctListOfLinks.get(i).getX().replace("&", "&") + "\" target=\"" + distinctListOfLinks.get(i).getY().replace("&", "&") + "\"/>\n"); } sc.ecrire("\t\t</edges>\n"); sc.ecrire("\t</graph>\n"); sc.ecrire("</gexf>"); sc.fermer(); PreviewJFrame p = new PreviewJFrame(); p.script(); /*PARTIE GRAPHE DES MENTIONS*/ //NE PAS OUBLIE LE COUP DE REMPLACER LES .replace("&", "&") POUR LE XML /*Set<String> users = new HashSet<>(); HashMap<DuoKey, Integer> map; map = new HashMap<DuoKey, Integer>(); DuoKey duokey; for (int i = 0; i < TweetManager.getTweets(criteria).size(); i++) { System.out.println(i); t = TweetManager.getTweets(criteria).get(i); users.add(t.getUsername()); if(!t.getMentions().isEmpty()){ for(String target : t.getMentions().split(" ")){ target = target.replaceFirst("@", ""); users.add(target); duokey = new DuoKey(t.getUsername(), target); if(map.get(duokey) != null){ map.put(duokey, map.get(duokey)+1); }else{ map.put(duokey, 1); } } } } Scribe s = new Scribe(); s.detruireFichier("tweets.gexf"); s.ouvrir("tweets.gexf"); s.ecrire("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); s.ecrire("<gexf xmlns=\"http://www.gexf.net/1.2draft/gexf.xsd\" version=\"1.2\" xmlns:viz=\"http://www.gexf.net/1.1draft/viz\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd\">\n"); s.ecrire("\t<meta lastmodifieddate=\"2017-02-17\">\n"); s.ecrire("\t\t<creator>Pirboss</creator>\n"); s.ecrire("\t\t<description>Test v1</description>\n"); s.ecrire("\t</meta>\n"); s.ecrire("\t<graph defaultedgetype=\"directed\" mode=\"static\">\n"); s.ecrire("\t\t<nodes>\n"); ArrayList distinctList = new ArrayList(users); for(int i=0; i<distinctList.size(); i++){ s.ecrire("\t\t\t<node id=\""+i+"\" label=\""+distinctList.get(i)+"\"/>\n"); } s.ecrire("\t\t</nodes>\n"); s.ecrire("\t\t<edges>\n"); Iterator ite = map.entrySet().iterator(); int jj=0; while (ite.hasNext()) { Map.Entry pair = (Map.Entry)ite.next(); s.ecrire("\t\t\t<edge id=\""+(jj++)+"\" source=\""+distinctList.indexOf(((DuoKey)pair.getKey()).getX())+"\" target=\""+distinctList.indexOf(((DuoKey)pair.getKey()).getY())+"\" weight=\""+pair.getValue()+"\"/>\n"); ite.remove(); // avoids a ConcurrentModificationException } s.ecrire("\t\t</edges>\n"); s.ecrire("\t</graph>\n"); s.ecrire("</gexf>"); s.fermer(); PreviewJFrame pr = new PreviewJFrame(); pr.script();*/ }
From source file:twitter.crawler.TwitterCrawler.java
public static void main(String[] args) { try {// w ww. j a va 2 s.c o m // Authorise the library ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey("AhoydO8uSe4v8NEq7j2ISGFlq"); cb.setOAuthConsumerSecret("ptKEYwq3G9vpFkqAhvwFLSWFcBW8U1SfqycECwK4cH6wThVba6"); cb.setOAuthAccessToken("778240255577194496-taafqDIHebrg972oxT5kTqcNd3Uojod"); cb.setOAuthAccessTokenSecret("DMRmeRahnLJRvCBIGQGTaTzE6Pr3PAZMgMsfWIT5ue3PD"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); User user = twitter.verifyCredentials(); // Get main user long cursor = -1; // Print user profile System.out.println("@" + user.getScreenName()); System.out.println(user.getId()); System.out.println(user.getProfileImageURL()); System.out.println(user.getFriendsCount() + " friends."); System.out.println("-------"); // Print Home Timeline List<Status> statuses = twitter.getHomeTimeline(); System.out.println("Showing @" + user.getScreenName() + "'s home timeline."); for (Status status : statuses) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } //Print followers System.out.println("-------"); System.out.println("Showing Follwers:"); PagableResponseList<User> followers; //do //{ followers = twitter.getFollowersList(user.getScreenName(), cursor); for (User follower : followers) { System.out.println("@" + follower.getScreenName()); } //} //while ((cursor = followers.getNextCursor())!=-1); //Print follwees System.out.println("-------"); System.out.println("Showing Followees:"); PagableResponseList<User> followees; do { followees = twitter.getFriendsList(user.getScreenName(), cursor); for (User followee : followees) { System.out.println("@" + followee.getScreenName()); } } while ((cursor = followees.getNextCursor()) != -1); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }