List of usage examples for twitter4j User getScreenName
String getScreenName();
From source file:Demo.java
/** * Main method.//from w w w . ja va 2 s . co m * * @param args * @throws TwitterException */ public static void main(String[] args) throws TwitterException, IOException { // The TwitterFactory object provides an instance of a Twitter object // via the getInstance() method. The Twitter object is the API consumer. // It has the methods for interacting with the Twitter API. TwitterFactory tf = new TwitterFactory(); Twitter twitter = tf.getInstance(); boolean keepItGoinFullSteam = true; do { // Main menu Scanner input = new Scanner(System.in); System.out.print("\n--------------------" + "\nH. Home Timeline\nS. Search\nT. Tweet" + "\n--------------------" + "\nA. Get Access Token\nQ. Quit" + "\n--------------------\n> "); String choice = input.nextLine(); try { // Home Timeline if (choice.equalsIgnoreCase("H")) { // Display the user's screen name. User user = twitter.verifyCredentials(); System.out.println("\n@" + user.getScreenName() + "'s timeline:"); // Display recent tweets from the Home Timeline. for (Status status : twitter.getHomeTimeline()) { System.out.println("\n@" + status.getUser().getScreenName() + ": " + status.getText()); } } // Search else if (choice.equalsIgnoreCase("S")) { // Ask the user for a search string. System.out.print("\nSearch: "); String searchStr = input.nextLine(); // Create a Query object. Query query = new Query(searchStr); // Send API request to execute a search with the given query. QueryResult result = twitter.search(query); // Display search results. result.getTweets().stream().forEach((Status status) -> { System.out.println("\n@" + status.getUser().getName() + ": " + status.getText()); }); } // Tweet else if (choice.equalsIgnoreCase("T")) { boolean isOkayLength = true; String tweet; do { // Ask the user for a tweet. System.out.print("\nTweet: "); tweet = input.nextLine(); // Ensure the tweet length is okay. if (tweet.length() > 140) { System.out.println("Too long! Keep it under 140."); isOkayLength = false; } } while (isOkayLength == false); // Send API request to create a new tweet. Status status = twitter.updateStatus(tweet); System.out.println("Just tweeted: \"" + status.getText() + "\""); } // Get Access Token else if (choice.equalsIgnoreCase("A")) { // First, we ask Twitter for a request token. RequestToken reqToken = twitter.getOAuthRequestToken(); System.out.println("\nRequest token: " + reqToken.getToken() + "\nRequest token secret: " + reqToken.getTokenSecret()); AccessToken accessToken = null; while (accessToken == null) { // The authorization URL sends the request token to Twitter in order // to request an access token. At this point, Twitter asks the user // to authorize the request. If the user authorizes, then Twitter // provides a PIN. System.out .print("\nOpen this URL in a browser: " + "\n " + reqToken.getAuthorizationURL() + "\n" + "\nAuthorize the app, then enter the PIN here: "); String pin = input.nextLine(); try { // We use the provided PIN to get the access token. The access // token allows this app to access the user's account without // knowing his/her password. accessToken = twitter.getOAuthAccessToken(reqToken, pin); } catch (TwitterException te) { System.out.println(te.getMessage()); } } System.out.println("\nAccess token: " + accessToken.getToken() + "\nAccess token secret: " + accessToken.getTokenSecret() + "\nSuccess!"); } // Quit else if (choice.equalsIgnoreCase("Q")) { keepItGoinFullSteam = false; GeoApiContext context = new GeoApiContext() .setApiKey("AIzaSyArz1NljiDpuOriFWalOerYEdHOyi8ow8Y"); System.out.println(GeocodingApi.geocode(context, "Sigma Phi Epsilon, Lincoln, Nebraska, USA") .await()[0].geometry.location.toString()); System.out.println(GeocodingApi.geocode(context, "16th and R, Lincoln, Nebraska, USA") .await()[0].geometry.location.toString()); File htmlFile = new File("map.html"); Desktop.getDesktop().browse(htmlFile.toURI()); } // Bad choice else { System.out.println("Invalid option."); } } catch (IllegalStateException ex) { System.out.println(ex.getMessage()); } catch (Exception ex) { System.out.println(ex.getMessage()); } } while (keepItGoinFullSteam == true); }
From source file:GetTweetsAndSaveToFile.java
License:Apache License
/** * Usage: java twitter4j.examples.user.ShowUser [screen name] * * @param args message//w w w . j a v a 2s . c o m * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.user.ShowUser [screen name]"); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer("men2JyLEaAsxcbfmgzOAwUnTp", "2AGN0ie9TfCDJyWeH8qhTLtMhqRvRlNBtQU3lAP2M8k3Xk1KWl"); RequestToken requestToken = twitter.getOAuthRequestToken(); System.out.println("Authorization URL: \n" + requestToken.getAuthorizationURL()); AccessToken accessToken = new AccessToken("2811255124-zigkuv8MwDQbr5s9HdjLRSbg8aCOyxeD2gYGMfH", "D7jFABWHQa8QkTWwgYj1ISUbWP8twdfbzNgYkXI3jwySR"); twitter.setOAuthAccessToken(accessToken); /* BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (null == accessToken) { System.out.println("Open the following URL and grant access to your account:"); System.out.println(requestToken.getAuthorizationURL()); System.out.print("Enter the PIN(if available) and hit enter after you granted access.[PIN]:"); String pin = br.readLine(); try { if (pin.length() > 0) { accessToken = twitter.getOAuthAccessToken(requestToken, pin); } else { accessToken = twitter.getOAuthAccessToken(requestToken); } } catch (TwitterException te) { if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else { te.printStackTrace(); } } } */ System.out.println("Got access token."); System.out.println("Access token: " + accessToken.getToken()); System.out.println("Access token secret: " + accessToken.getTokenSecret()); 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()); } FileWriter file = new FileWriter("./" + user.getScreenName() + "_Tweets.txt"); List<Status> list = twitter.getHomeTimeline(); for (Status each : list) { file.write("Sent by: @" + each.getUser().getScreenName() + " - " + each.getUser().getName() + "---" + each.getText() + "\n"); } file.close(); System.exit(0); } catch (Exception te) { te.printStackTrace(); System.exit(-1); } }
From source file:DestroyFriendship.java
License:Apache License
/** * Usage: java twitter4j.examples.friendship.DestroyFriendship [screen name] * * @param args message// www . ja v a2 s.com */ public void destroyFriendship() { ShowFriendshi df = new ShowFriendshi(); ArrayList<Long> getFilteredtarget = df.showFriendship(); try { Twitter twitter = new TwitterFactory().getInstance(); User user; String get; DefaultListModel m1 = new DefaultListModel(); for (Long target : getFilteredtarget) { user = twitter.showUser(target); get = user.getScreenName(); if (!get.equalsIgnoreCase("prometheanBrain") && !get.equalsIgnoreCase("tweetrackdevs")) { m1.addElement(get); twitter.destroyFriendship(target); } System.out.println("Successfully unfollowed [" + target + "]."); } MainActivity.deletedList.setModel(m1); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to unfollow: " + te.getMessage()); } }
From source file:aic2013.common.entities.TwitterUser.java
public TwitterUser(User user) { id = user.getId();//from w w w.j a v a2 s . c o m name = user.getName(); screenName = user.getScreenName(); lang = user.getLang(); followersCount = user.getFollowersCount(); statusesCount = user.getStatusesCount(); friendsCount = user.getFriendsCount(); favouritesCount = user.getFavouritesCount(); listedCount = user.getListedCount(); }
From source file:aic2013.extractor.entities.TwitterUser.java
public TwitterUser(User user) { id = user.getId();//from w w w. jav a 2s . c o m name = user.getName(); screenName = user.getScreenName(); language = user.getLang(); followersCount = user.getFollowersCount(); statusesCount = user.getStatusesCount(); friendsCount = user.getFriendsCount(); favouritesCount = user.getFavouritesCount(); listedCount = user.getListedCount(); }
From source file:au.net.moon.tUtils.TUser.java
License:Open Source License
/** * Create a user object from a twitter4j user. * /* w ww.j av a2s .c om*/ * @param twitterUser * a twitter4j user object */ public TUser(twitter4j.User twitterUser) { id = twitterUser.getId(); name = twitterUser.getName(); screenName = twitterUser.getScreenName(); location = twitterUser.getLocation(); description = twitterUser.getDescription(); if (twitterUser.getProfileImageURL() != null) { profileImageUrl = twitterUser.getProfileImageURL().toString(); } else { profileImageUrl = ""; } if (twitterUser.getURL() != null) { url = twitterUser.getURL().toString(); } else { url = ""; } createdAt = twitterUser.getCreatedAt(); isProtected = twitterUser.isProtected(); followersCount = twitterUser.getFollowersCount(); // Not interested in users latest tweet, so just leave blank status = ""; profileBackgroundColor = twitterUser.getProfileBackgroundColor(); profileTextColor = twitterUser.getProfileTextColor(); profileLinkColor = twitterUser.getProfileLinkColor(); profileSidebarFillColor = twitterUser.getProfileSidebarFillColor(); profileSidebarBorderColor = twitterUser.getProfileSidebarBorderColor(); friendsCount = twitterUser.getFriendsCount(); favouritesCount = twitterUser.getFavouritesCount(); utcOffset = twitterUser.getUtcOffset(); timeZone = twitterUser.getTimeZone(); if (twitterUser.getOriginalProfileImageURL() != null) { profileBackgroundImageUrl = twitterUser.getOriginalProfileImageURL().toString(); } else { profileBackgroundImageUrl = ""; } isProfileBackgroundTiled = twitterUser.isProfileBackgroundTiled(); statusesCount = twitterUser.getStatusesCount(); isGeoEnabled = twitterUser.isGeoEnabled(); isVerified = twitterUser.isVerified(); // isFollowing = twitterUser.isFollowing(); isContributorsEnabled = twitterUser.isContributorsEnabled(); isProfileUseBackgroundImage = twitterUser.isProfileUseBackgroundImage(); isShowAllInLineMedia = twitterUser.isShowAllInlineMedia(); lang = twitterUser.getLang(); isTranslator = twitterUser.isTranslator(); listedCount = twitterUser.getListedCount(); isFollowRequestSent = twitterUser.isFollowRequestSent(); // TODO: Need to pass in the searchAPI id if I have it. searchAPI_userID = ""; }
From source file:br.com.porcelli.hornetq.integration.twitter.support.TweetMessageConverterSupport.java
License:Apache License
private static void buildUserData(final String prefix, final User user, ServerMessage msg) { msg.putStringProperty(prefix + TwitterConstants.KEY_USER_ID, read(user.getId())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_NAME, read(user.getName())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_SCREEN_NAME, read(user.getScreenName())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_LOCATION, read(user.getLocation())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_DESCRIPTION, read(user.getDescription())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_PROFILE_IMAGE_URL, read(user.getProfileImageURL())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_URL, read(user.getURL())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_LANG, read(user.getLang())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_PROTECTED, read(user.isProtected())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_FOLLOWERS_COUNT, read(user.getFollowersCount())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_FRIENDS_COUNT, read(user.getFriendsCount())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_CREATED_AT, read(user.getCreatedAt())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_FAVOURITES_COUNT, read(user.getFavouritesCount())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_UTC_OFFSET, read(user.getUtcOffset())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_TIME_ZONE, read(user.getTimeZone())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_STATUSES_COUNT, read(user.getStatusesCount())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_VERIFIED, read(user.isVerified())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_CONTRIBUTORS_ENABLED, read(user.isContributorsEnabled())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_GEO_ENABLED, read(user.isGeoEnabled())); }
From source file:cloudcomputebot.Input.Decipher.java
License:Open Source License
public static void handleInput(Status status, User sender) throws FileNotFoundException, IOException, TwitterException { String[] lines = argsNoComments(status.getText()); if (lines.length > 0) { String cmd = lines[0];/*from w w w . ja v a 2s. c om*/ if (cmd.equalsIgnoreCase(validCmds[0]) || cmd.equalsIgnoreCase(validCmds[1])) { String[] fractalInputStream = new String[lines.length - 1]; int c = 0; for (int i = 1; i < lines.length; i++) { fractalInputStream[c] = lines[i]; c++; } ImageCreator fractalCreator = new ImageCreator(); fractalCreator.setArgsForTwitter(fractalInputStream); BufferedImage fractal = fractalCreator.drawFractal(); StatusUpdate retweet = new StatusUpdate("@" + sender.getScreenName()); File img = new File("image.gif"); ImageIO.write(fractal, "gif", img); retweet.setMedia(img); CloudComputeBot.t.updateStatus(retweet); } } }
From source file:com.ahuralab.mozaic.db.Message.java
License:Open Source License
public static Message create(Status status) { User user = status.getUser(); return new Message(status.getText(), status.getCreatedAt(), status.getRetweetCount(), user.getId(), user.getName(), user.getScreenName(), user.getLocation(), user.getDescription(), user.getProfileImageURL(), status.getId(), 0, 0, user.getFollowersCount(), user.getStatusesCount()); }
From source file:com.appdynamics.alerts.twitter.TwitterAlert.java
License:Apache License
/** * Check for rate limit and protected status. Post status if permitted, log status otherwise *//*w w w.j a va 2s . c om*/ private static void postUpdate() { try { if (!isLimitReached()) { User user = twitter.verifyCredentials(); if (user.isProtected()) { twitter.updateStatus(createStatus(true)); } else { logger.error( "User @" + user.getScreenName() + " status is not protected, aborting status update"); } } else { logger.warn("Twitter rate limit reached, status update ignored until next reset"); logger.info("Ignored tweet: " + createStatus(false)); } } catch (TwitterException e) { if (e.getStatusCode() == 403 || e.getStatusCode() == 400) { logger.error(e.getErrorMessage()); } else { logger.error(e); } } }