List of usage examples for twitter4j User getScreenName
String getScreenName();
From source file:twitter4j.examples.user.ShowUser.java
License:Apache License
/** * Usage: java twitter4j.examples.user.ShowUser [screen name] * * @param args message//from www. ja v a2s .co m */ 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:TwitterDownload.TwitterExel.java
public static String writeFollowers(long ID, List<User> followers, String path) { try {//from www. ja va 2 s .c o m path = path + "Tweets"; File theDir = new File(path); // if the directory does not exist, create it if (!theDir.exists()) { theDir.mkdir(); } String exlPath = path + "/" + ID + ".xls"; File exlFile = new File(exlPath); WritableWorkbook writableWorkbook = null; WritableSheet writableSheet = null; int i = 0; while (exlFile.exists()) { i++; exlPath = path + "/" + ID + "_" + i + ".xls"; exlFile = new File(exlPath); } writableWorkbook = Workbook.createWorkbook(exlFile); writableSheet = writableWorkbook.createSheet("FerretData", 0); try { Workbook existing = Workbook.getWorkbook(exlFile); writableWorkbook = Workbook.createWorkbook(exlFile, existing); writableSheet = writableWorkbook.getSheet(0); } catch (BiffException be) { } //Create Cells with contents of different data types. //Also specify the Cell coordinates in the constructor i = 0; i = writableSheet.getRows(); if (i == 0) { Label userName = new Label(0, 0, "User Name"); Label name = new Label(1, 0, "Name"); Label desc = new Label(2, 0, "Description"); Label date = new Label(3, 0, "Created Date"); Label uID = new Label(4, 0, "Twitter ID"); Label link = new Label(5, 0, "Link"); //Add the created Cells to the sheet writableSheet.addCell(userName); writableSheet.addCell(name); writableSheet.addCell(desc); writableSheet.addCell(date); writableSheet.addCell(uID); writableSheet.addCell(link); i = 1; } for (int j = 0; j < followers.size(); j++) { User u = followers.get(j); Label userName = new Label(0, i + j, u.getScreenName()); Label name = new Label(1, i + j, u.getName()); Label desc = new Label(2, i + j, u.getDescription()); DateTime date = new DateTime(3, i + j, u.getCreatedAt()); Label uID = new Label(4, i + j, Long.toString(u.getId())); String link = "https://twitter.com/" + u.getScreenName(); URL url = new URL(link); WritableHyperlink hl = new WritableHyperlink(5, j + 1, url); //Add the created Cells to the sheet writableSheet.addCell(userName); writableSheet.addCell(name); writableSheet.addCell(desc); writableSheet.addCell(date); writableSheet.addCell(uID); writableSheet.addHyperlink(hl); } //Write and close the workbook writableWorkbook.write(); writableWorkbook.close(); return exlPath; } catch (IOException e) { e.printStackTrace(); } catch (RowsExceededException e) { e.printStackTrace(); } catch (WriteException e) { e.printStackTrace(); } return null; }
From source file:TwitterLookUpUsers.LookupUsers.java
License:Apache License
public static void main(String[] args) throws InterruptedException { Postgresql.DBBaglan();//from w w w . j a v a 2 s.c om 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 w w .j a v a 2s . com 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) { /*****//* www . j a v a2 s . co 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:twitterrest.Followersids.java
License:Apache License
public static void main(String[] args) throws TwitterException { String ScreenName = "anondroid5";//?? // ?/*from w w w . j a va 2s . c o m*/ 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:twitterrest.GetHomeTimeline.java
License:Apache License
public static void main(String[] args) { try {/*from w w w.j a va 2s . co m*/ // ? Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY) .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN) .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build(); Twitter twitter = new TwitterFactory(configuration).getInstance(); User user = twitter.verifyCredentials(); 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()); } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
From source file:twittynumnum.FutureListener.java
public void listen(String[] keywords) { StatusListener listener = new StatusListener() { @Override/*from ww w. j a v a2 s. co m*/ public void onException(Exception arg0) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onStatus(Status status) { User user = status.getUser(); String username = user.getScreenName(); String profileLocation = user.getLocation(); long tweetId = status.getId(); String content = status.getText(); Date tweetDate = status.getCreatedAt(); out.print(tweetId + "\t" + tweetDate + "\t" + username + "\t" + profileLocation + "\t" + content.replaceAll("\n", "/n") + "\n"); } @Override public void onTrackLimitationNotice(int arg0) { } @Override public void onStallWarning(StallWarning sw) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }; FilterQuery filter = new FilterQuery(); filter.track(keywords); twitterStream.addListener(listener); twitterStream.filter(filter); }
From source file:uk.ac.susx.tag.method51.twitter.Tweet.java
License:Apache License
public Tweet(Status status) { this();//from w w w .ja v a 2 s . c o m created = status.getCreatedAt(); id = status.getId(); text = status.getText(); inReplyToStatusId = status.getInReplyToStatusId(); inReplyToUserId = status.getInReplyToUserId(); originalText = null; retweetId = -1; isTruncated = status.isTruncated(); isRetweet = status.isRetweet(); Status entities = status; if (isRetweet) { Status origTweet = status.getRetweetedStatus(); entities = origTweet; retweetId = origTweet.getId(); originalText = text; text = origTweet.getText(); } StringBuilder sb = new StringBuilder(); for (HashtagEntity e : entities.getHashtagEntities()) { sb.append(e.getText()); sb.append(" "); } hashtags = sb.toString(); sb = new StringBuilder(); for (UserMentionEntity e : entities.getUserMentionEntities()) { sb.append(e.getScreenName()); sb.append(" "); } mentions = sb.toString(); sb = new StringBuilder(); for (URLEntity e : entities.getURLEntities()) { //String url = e.getURL(); String url = e.getExpandedURL(); if (url == null) { url = e.getURL(); if (url != null) { sb.append(url); } } else { sb.append(url); } sb.append(" "); } urls = sb.toString(); sb = new StringBuilder(); //seems to be null if no entries MediaEntity[] mediaEntities = entities.getMediaEntities(); if (mediaEntities != null) { for (MediaEntity e : mediaEntities) { String url = e.getMediaURL(); sb.append(url); sb.append(" "); } mediaUrls = sb.toString(); } else { mediaUrls = ""; } received = new Date(); source = status.getSource(); GeoLocation geoLoc = status.getGeoLocation(); Place place = status.getPlace(); if (geoLoc != null) { geoLong = geoLoc.getLongitude(); geoLat = geoLoc.getLatitude(); } else if (place != null && place.getBoundingBoxCoordinates() != null && place.getBoundingBoxCoordinates().length > 0) { GeoLocation[] locs = place.getBoundingBoxCoordinates()[0]; double avgLat = 0; double avgLon = 0; for (GeoLocation loc : locs) { avgLat += loc.getLatitude(); avgLon += loc.getLongitude(); } avgLat /= locs.length; avgLon /= locs.length; geoLat = avgLat; geoLong = avgLon; } else { geoLong = null; geoLat = null; } twitter4j.User user = status.getUser(); if (user != null) { userId = user.getId(); location = user.getLocation(); screenName = user.getScreenName(); following = user.getFriendsCount(); name = user.getName(); lang = user.getLang(); timezone = user.getTimeZone(); userCreated = user.getCreatedAt(); followers = user.getFollowersCount(); statusCount = user.getStatusesCount(); description = user.getDescription(); url = user.getURL(); utcOffset = user.getUtcOffset(); favouritesCount = user.getFavouritesCount(); this.user = new User(user); } }