List of usage examples for twitter4j User getScreenName
String getScreenName();
From source file:org.getlantern.firetweet.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues createAccount(final Configuration conf, final String basicUsername, final String basicPassword, final User user, final int color, final String apiUrlFormat, final boolean noVersionSuffix) { if (user == null || user.getId() <= 0) return null; final ContentValues values = new ContentValues(); if (basicUsername == null || basicPassword == null) return null; values.put(Accounts.BASIC_AUTH_USERNAME, basicUsername); values.put(Accounts.BASIC_AUTH_PASSWORD, basicPassword); values.put(Accounts.AUTH_TYPE, Accounts.AUTH_TYPE_BASIC); values.put(Accounts.ACCOUNT_ID, user.getId()); values.put(Accounts.SCREEN_NAME, user.getScreenName()); values.put(Accounts.NAME, user.getName()); values.put(Accounts.PROFILE_IMAGE_URL, user.getProfileImageUrlHttps()); values.put(Accounts.PROFILE_BANNER_URL, user.getProfileBannerImageUrl()); values.put(Accounts.COLOR, color);// w w w . j a v a 2 s . c o m values.put(Accounts.IS_ACTIVATED, 1); values.put(Accounts.API_URL_FORMAT, apiUrlFormat); values.put(Accounts.NO_VERSION_SUFFIX, noVersionSuffix); return values; }
From source file:org.getlantern.firetweet.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues createAccount(final Configuration conf, final AccessToken accessToken, final User user, final int authType, final int color, final String apiUrlFormat, final boolean sameOAuthSigningUrl, final boolean noVersionSuffix) { if (user == null || user.getId() <= 0 || accessToken == null || user.getId() != accessToken.getUserId()) return null; final ContentValues values = new ContentValues(); values.put(Accounts.OAUTH_TOKEN, accessToken.getToken()); values.put(Accounts.OAUTH_TOKEN_SECRET, accessToken.getTokenSecret()); values.put(Accounts.CONSUMER_KEY, conf.getOAuthConsumerKey()); values.put(Accounts.CONSUMER_SECRET, conf.getOAuthConsumerSecret()); values.put(Accounts.AUTH_TYPE, authType); values.put(Accounts.ACCOUNT_ID, user.getId()); values.put(Accounts.SCREEN_NAME, user.getScreenName()); values.put(Accounts.NAME, user.getName()); values.put(Accounts.PROFILE_IMAGE_URL, user.getProfileImageUrlHttps()); values.put(Accounts.PROFILE_BANNER_URL, user.getProfileBannerImageUrl()); values.put(Accounts.COLOR, color);/* ww w . jav a 2 s. c o m*/ values.put(Accounts.IS_ACTIVATED, 1); values.put(Accounts.API_URL_FORMAT, apiUrlFormat); values.put(Accounts.SAME_OAUTH_SIGNING_URL, sameOAuthSigningUrl); values.put(Accounts.NO_VERSION_SUFFIX, noVersionSuffix); return values; }
From source file:org.getlantern.firetweet.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues createAccount(final Configuration conf, final User user, final int color, final String apiUrlFormat, final boolean noVersionSuffix) { if (user == null || user.getId() <= 0) return null; final ContentValues values = new ContentValues(); values.put(Accounts.AUTH_TYPE, Accounts.AUTH_TYPE_TWIP_O_MODE); values.put(Accounts.ACCOUNT_ID, user.getId()); values.put(Accounts.SCREEN_NAME, user.getScreenName()); values.put(Accounts.NAME, user.getName()); values.put(Accounts.PROFILE_IMAGE_URL, (user.getProfileImageUrlHttps())); values.put(Accounts.PROFILE_BANNER_URL, (user.getProfileBannerImageUrl())); values.put(Accounts.COLOR, color);//from ww w. j a v a2s. co m values.put(Accounts.IS_ACTIVATED, 1); values.put(Accounts.API_URL_FORMAT, apiUrlFormat); values.put(Accounts.NO_VERSION_SUFFIX, noVersionSuffix); return values; }
From source file:org.getlantern.firetweet.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues createCachedUser(final User user) { if (user == null || user.getId() <= 0) return null; final String profile_image_url = user.getProfileImageUrlHttps(); final String url = user.getURL(); final URLEntity[] urls = user.getURLEntities(); final ContentValues values = new ContentValues(); values.put(CachedUsers.USER_ID, user.getId()); values.put(CachedUsers.NAME, user.getName()); values.put(CachedUsers.SCREEN_NAME, user.getScreenName()); values.put(CachedUsers.PROFILE_IMAGE_URL, profile_image_url); values.put(CachedUsers.PROFILE_BANNER_URL, user.getProfileBannerImageUrl()); values.put(CachedUsers.CREATED_AT, user.getCreatedAt().getTime()); values.put(CachedUsers.IS_PROTECTED, user.isProtected()); values.put(CachedUsers.IS_VERIFIED, user.isVerified()); values.put(CachedUsers.IS_FOLLOWING, user.isFollowing()); values.put(CachedUsers.FAVORITES_COUNT, user.getFavouritesCount()); values.put(CachedUsers.FOLLOWERS_COUNT, user.getFollowersCount()); values.put(CachedUsers.FRIENDS_COUNT, user.getFriendsCount()); values.put(CachedUsers.STATUSES_COUNT, user.getStatusesCount()); values.put(CachedUsers.LISTED_COUNT, user.getListedCount()); values.put(CachedUsers.LOCATION, user.getLocation()); values.put(CachedUsers.DESCRIPTION_PLAIN, user.getDescription()); values.put(CachedUsers.DESCRIPTION_HTML, TwitterContentUtils.formatUserDescription(user)); values.put(CachedUsers.DESCRIPTION_EXPANDED, TwitterContentUtils.formatExpandedUserDescription(user)); values.put(CachedUsers.URL, url); if (url != null && urls != null && urls.length > 0) { values.put(CachedUsers.URL_EXPANDED, urls[0].getExpandedURL()); }//from w w w . j a v a2 s .co m values.put(CachedUsers.BACKGROUND_COLOR, ParseUtils.parseColor("#" + user.getProfileBackgroundColor(), 0)); values.put(CachedUsers.LINK_COLOR, ParseUtils.parseColor("#" + user.getProfileLinkColor(), 0)); values.put(CachedUsers.TEXT_COLOR, ParseUtils.parseColor("#" + user.getProfileTextColor(), 0)); return values; }
From source file:org.getlantern.firetweet.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues createDirectMessage(final DirectMessage message, final long accountId, final boolean isOutgoing) { if (message == null) return null; final ContentValues values = new ContentValues(); final User sender = message.getSender(), recipient = message.getRecipient(); if (sender == null || recipient == null) return null; final String sender_profile_image_url = sender.getProfileImageUrlHttps(); final String recipient_profile_image_url = recipient.getProfileImageUrlHttps(); values.put(DirectMessages.ACCOUNT_ID, accountId); values.put(DirectMessages.MESSAGE_ID, message.getId()); values.put(DirectMessages.MESSAGE_TIMESTAMP, message.getCreatedAt().getTime()); values.put(DirectMessages.SENDER_ID, sender.getId()); values.put(DirectMessages.RECIPIENT_ID, recipient.getId()); if (isOutgoing) { values.put(DirectMessages.CONVERSATION_ID, recipient.getId()); } else {/*w w w . ja va2s .c o m*/ values.put(DirectMessages.CONVERSATION_ID, sender.getId()); } final String text_html = TwitterContentUtils.formatDirectMessageText(message); values.put(DirectMessages.TEXT_HTML, text_html); values.put(DirectMessages.TEXT_PLAIN, message.getText()); values.put(DirectMessages.TEXT_UNESCAPED, toPlainText(text_html)); values.put(DirectMessages.IS_OUTGOING, isOutgoing); values.put(DirectMessages.SENDER_NAME, sender.getName()); values.put(DirectMessages.SENDER_SCREEN_NAME, sender.getScreenName()); values.put(DirectMessages.RECIPIENT_NAME, recipient.getName()); values.put(DirectMessages.RECIPIENT_SCREEN_NAME, recipient.getScreenName()); values.put(DirectMessages.SENDER_PROFILE_IMAGE_URL, sender_profile_image_url); values.put(DirectMessages.RECIPIENT_PROFILE_IMAGE_URL, recipient_profile_image_url); final ParcelableMedia[] mediaArray = ParcelableMedia.fromEntities(message); if (mediaArray != null) { values.put(DirectMessages.MEDIA_LIST, SimpleValueSerializer.toSerializedString(mediaArray)); } return values; }
From source file:org.getlantern.firetweet.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues createStatus(final Status orig, final long accountId) { if (orig == null || orig.getId() <= 0) return null; final ContentValues values = new ContentValues(); values.put(Statuses.ACCOUNT_ID, accountId); values.put(Statuses.STATUS_ID, orig.getId()); values.put(Statuses.STATUS_TIMESTAMP, orig.getCreatedAt().getTime()); final Status status; if (orig.isRetweet()) { final Status retweetedStatus = orig.getRetweetedStatus(); final User retweetUser = orig.getUser(); final long retweetedById = retweetUser.getId(); values.put(Statuses.RETWEET_ID, retweetedStatus.getId()); values.put(Statuses.RETWEET_TIMESTAMP, retweetedStatus.getCreatedAt().getTime()); values.put(Statuses.RETWEETED_BY_USER_ID, retweetedById); values.put(Statuses.RETWEETED_BY_USER_NAME, retweetUser.getName()); values.put(Statuses.RETWEETED_BY_USER_SCREEN_NAME, retweetUser.getScreenName()); values.put(Statuses.RETWEETED_BY_USER_PROFILE_IMAGE, (retweetUser.getProfileImageUrlHttps())); values.put(Statuses.IS_RETWEET, true); if (retweetedById == accountId) { values.put(Statuses.MY_RETWEET_ID, orig.getId()); } else {// w w w .ja va 2 s. c o m values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet()); } status = retweetedStatus; } else if (orig.isQuote()) { final Status quotedStatus = orig.getQuotedStatus(); final User quoteUser = orig.getUser(); final long quotedById = quoteUser.getId(); values.put(Statuses.QUOTE_ID, quotedStatus.getId()); final String textHtml = TwitterContentUtils.formatStatusText(orig); values.put(Statuses.QUOTE_TEXT_HTML, textHtml); values.put(Statuses.QUOTE_TEXT_PLAIN, orig.getText()); values.put(Statuses.QUOTE_TEXT_UNESCAPED, toPlainText(textHtml)); values.put(Statuses.QUOTE_TIMESTAMP, orig.getCreatedAt().getTime()); values.put(Statuses.QUOTE_SOURCE, orig.getSource()); values.put(Statuses.QUOTED_BY_USER_ID, quotedById); values.put(Statuses.QUOTED_BY_USER_NAME, quoteUser.getName()); values.put(Statuses.QUOTED_BY_USER_SCREEN_NAME, quoteUser.getScreenName()); values.put(Statuses.QUOTED_BY_USER_PROFILE_IMAGE, quoteUser.getProfileImageUrlHttps()); values.put(Statuses.QUOTED_BY_USER_IS_VERIFIED, quoteUser.isVerified()); values.put(Statuses.QUOTED_BY_USER_IS_PROTECTED, quoteUser.isProtected()); values.put(Statuses.IS_QUOTE, true); if (quotedById == accountId) { values.put(Statuses.MY_QUOTE_ID, orig.getId()); // } else { // values.put(Statuses.MY_QUOTE_ID, orig.getCurrentUserRetweet()); } status = quotedStatus; } else { values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet()); status = orig; } final User user = status.getUser(); final long userId = user.getId(); final String profileImageUrl = (user.getProfileImageUrlHttps()); final String name = user.getName(), screenName = user.getScreenName(); values.put(Statuses.USER_ID, userId); values.put(Statuses.USER_NAME, name); values.put(Statuses.USER_SCREEN_NAME, screenName); values.put(Statuses.IS_PROTECTED, user.isProtected()); values.put(Statuses.IS_VERIFIED, user.isVerified()); values.put(Statuses.USER_PROFILE_IMAGE_URL, profileImageUrl); values.put(CachedUsers.IS_FOLLOWING, user.isFollowing()); final String textHtml = TwitterContentUtils.formatStatusText(status); values.put(Statuses.TEXT_HTML, textHtml); values.put(Statuses.TEXT_PLAIN, status.getText()); values.put(Statuses.TEXT_UNESCAPED, toPlainText(textHtml)); values.put(Statuses.RETWEET_COUNT, status.getRetweetCount()); values.put(Statuses.REPLY_COUNT, status.getReplyCount()); values.put(Statuses.FAVORITE_COUNT, status.getFavoriteCount()); values.put(Statuses.DESCENDENT_REPLY_COUNT, status.getDescendentReplyCount()); values.put(Statuses.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId()); values.put(Statuses.IN_REPLY_TO_USER_ID, status.getInReplyToUserId()); values.put(Statuses.IN_REPLY_TO_USER_NAME, TwitterContentUtils.getInReplyToName(status)); values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, status.getInReplyToScreenName()); values.put(Statuses.SOURCE, status.getSource()); values.put(Statuses.IS_POSSIBLY_SENSITIVE, status.isPossiblySensitive()); final GeoLocation location = status.getGeoLocation(); if (location != null) { values.put(Statuses.LOCATION, ParcelableLocation.toString(location.getLatitude(), location.getLongitude())); } final Place place = status.getPlace(); if (place != null) { values.put(Statuses.PLACE_FULL_NAME, place.getFullName()); } values.put(Statuses.IS_FAVORITE, status.isFavorited()); final ParcelableMedia[] media = ParcelableMedia.fromEntities(status); if (media != null) { values.put(Statuses.MEDIA_LIST, SimpleValueSerializer.toSerializedString(media)); } final ParcelableUserMention[] mentions = ParcelableUserMention.fromStatus(status); if (mentions != null) { values.put(Statuses.MENTIONS_LIST, SimpleValueSerializer.toSerializedString(mentions)); } final ParcelableCardEntity card = ParcelableCardEntity.fromCardEntity(status.getCard(), accountId); if (card != null) { values.put(Statuses.CARD_NAME, card.name); values.put(Statuses.CARD, JSONSerializer.toJSONObjectString(card)); } return values; }
From source file:org.getlantern.firetweet.util.TwitterWrapper.java
License:Open Source License
@NonNull public static User showUserAlternative(final Twitter twitter, final long id, final String screenName) throws TwitterException { final String searchScreenName; if (screenName != null) { searchScreenName = screenName;//from w w w. j ava2s. c om } else if (id != -1) { searchScreenName = twitter.showFriendship(twitter.getId(), id).getTargetUserScreenName(); } else throw new IllegalArgumentException(); final Paging paging = new Paging(); paging.count(1); if (id != -1) { final ResponseList<Status> timeline = twitter.getUserTimeline(id, paging); for (final Status status : timeline) { final User user = status.getUser(); if (user.getId() == id) return user; } } else { final ResponseList<Status> timeline = twitter.getUserTimeline(screenName, paging); for (final Status status : timeline) { final User user = status.getUser(); if (searchScreenName.equalsIgnoreCase(user.getScreenName())) return user; } } for (final User user : twitter.searchUsers(searchScreenName, 1)) { if (user.getId() == id || searchScreenName.equalsIgnoreCase(user.getScreenName())) return user; } throw new TwitterException("can't find user"); }
From source file:org.getlantern.firetweet.util.Utils.java
License:Open Source License
public static String getUserName(final Context context, final User user) { if (context == null || user == null) return null; return UserColorNameUtils.getDisplayName(context, user.getId(), user.getName(), user.getScreenName()); }
From source file:org.graylog2.inputs.twitter.TwitterCodec.java
License:Open Source License
private Message createMessageFromStatus(final Status status) { final Message message = new Message(status.getText(), "twitter.com", new DateTime(status.getCreatedAt())); message.addField("facility", "Tweets"); message.addField("level", 6); message.addField("tweet_id", status.getId()); message.addField("tweet_is_retweet", Boolean.toString(status.isRetweet())); message.addField("tweet_favorite_count", status.getFavoriteCount()); message.addField("tweet_retweet_count", status.getRetweetCount()); message.addField("tweet_language", status.getLang()); final GeoLocation geoLocation = status.getGeoLocation(); if (geoLocation != null) { message.addField("tweet_geo_long", geoLocation.getLongitude()); message.addField("tweet_geo_lat", geoLocation.getLatitude()); }// w w w.j av a2 s . c o m final User user = status.getUser(); if (user != null) { message.addField("tweet_url", "https://twitter.com/" + user.getScreenName() + "/status/" + status.getId()); message.addField("user_id", user.getId()); message.addField("user_name", user.getScreenName()); message.addField("user_description", user.getDescription()); message.addField("user_timezone", user.getTimeZone()); message.addField("user_utc_offset", user.getUtcOffset()); message.addField("user_location", user.getLocation()); message.addField("user_language", user.getLang()); message.addField("user_url", user.getURL()); message.addField("user_followers", user.getFollowersCount()); message.addField("user_tweets", user.getStatusesCount()); message.addField("user_favorites", user.getFavouritesCount()); } return message; }
From source file:org.jibble.simplewebserver.RequestThread.java
License:Open Source License
public void run() { InputStream reader = null;//from w w w . ja v a 2s . c o m try { _socket.setSoTimeout(30000); BufferedReader in = new BufferedReader(new InputStreamReader(_socket.getInputStream())); BufferedOutputStream out = new BufferedOutputStream(_socket.getOutputStream()); String request = in.readLine(); if (request == null || !request.startsWith("GET ") || !(request.endsWith(" HTTP/1.0") || request.endsWith("HTTP/1.1"))) { // Invalid request type (no "GET") sendError(out, 500, "Invalid Method."); return; } String path = request.substring(4, request.length() - 9); if (path.indexOf("collection") > -1) { Twitter twitter = TF.getInstance(); try { // Uncomment to send tweet and test credentials // Status status = twitter.updateStatus("Try this tweet."); String id = "custom-549647846786347008"; int collectionIdIdx = path.indexOf("custom-"); if (collectionIdIdx > 0) { id = path.substring(collectionIdIdx); } List<Status> statuses = twitter.getCustomTimeline(id); sendHeader(out, 200, "text/html", -1, System.currentTimeMillis()); String title = "Tweets for '" + id + "'"; out.write(("<html><head><title>" + title + "</title></head><body><h3>" + title + "</h3><p>\n") .getBytes()); for (int i = 0; i < statuses.size(); i++) { Status status = statuses.get(i); User user = status.getUser(); String blockquote = "<blockquote class=\"twitter-tweet\" lang=\"en\"><p>" + status.getText() + "</p>— " + user.getName() + " (" + user.getScreenName() + ") <a href=\"https://twitter.com/" + user.getScreenName() + "/status/" + status.getId() + "\">DATE5</a></blockquote>"; out.write((blockquote + "<br>\n").getBytes()); } out.write(("</p><hr><p>" + SimpleWebServer.VERSION + "</p><script async src=\"//platform.twitter.com/widgets.js\" charset=\"utf-8\"></script></body><html>") .getBytes()); } catch (TwitterException e) { sendError(out, 500, "Invalid Method."); } out.flush(); out.close(); return; } File file = new File(_rootDir, URLDecoder.decode(path, "UTF-8")).getCanonicalFile(); if (file.isDirectory()) { // Check to see if there is an index file in the directory. File indexFile = new File(file, "index.html"); if (indexFile.exists() && !indexFile.isDirectory()) { file = indexFile; } } if (!file.toString().startsWith(_rootDir.toString())) { // Uh-oh, it looks like some lamer is trying to take a peek // outside of our web root directory. sendError(out, 403, "Permission Denied."); } else if (!file.exists()) { // The file was not found. sendError(out, 404, "File Not Found."); } else if (file.isDirectory()) { // print directory listing if (!path.endsWith("/")) { path = path + "/"; } File[] files = file.listFiles(); sendHeader(out, 200, "text/html", -1, System.currentTimeMillis()); String title = "Index of " + path; out.write( ("<html><head><title>" + title + "</title></head><body><h3>Index of " + path + "</h3><p>\n") .getBytes()); for (int i = 0; i < files.length; i++) { file = files[i]; String filename = file.getName(); String description = ""; if (file.isDirectory()) { description = "<DIR>"; } out.write(("<a href=\"" + path + filename + "\">" + filename + "</a> " + description + "<br>\n") .getBytes()); } out.write(("</p><hr><p>" + SimpleWebServer.VERSION + "</p></body><html>").getBytes()); } else { reader = new BufferedInputStream(new FileInputStream(file)); String contentType = (String) SimpleWebServer.MIME_TYPES.get(Utils.getExtension(file)); if (contentType == null) { contentType = "application/octet-stream"; } sendHeader(out, 200, contentType, file.length(), file.lastModified()); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = reader.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); } reader.close(); } out.flush(); out.close(); } catch (IOException e) { if (reader != null) { try { reader.close(); } catch (Exception anye) { // Do nothing. } } } }