List of usage examples for twitter4j User getScreenName
String getScreenName();
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
public void connect() throws TwitterException { initProperties();//w ww.j a va2s.co m ConfigurationBuilder config = new ConfigurationBuilder(); config.setOAuthConsumerKey(getOauthKey()); config.setOAuthConsumerSecret(getOauthSecret()); config.setOAuthAccessToken(getToken()); config.setOAuthAccessTokenSecret(getTokenSecret()); twitter4j.Twitter twitter = new TwitterFactory(config.build()).getInstance(); User user = twitter.verifyCredentials(); if (!this.userName.equals(user.getScreenName())) { this.userName = user.getScreenName(); saveProperties(null); } //AccessToken accessToken = new AccessToken(getToken(), getTokenSecret()); //twitter4j.Twitter twitter = new TwitterFactory().getInstance(accessToken); //twitter4j.Twitter twitter = new TwitterFactory().getInstance(getOauthKey(), getOauthSecret(), accessToken); //twitter4j.Twitter twitter = new TwitterFactory().getInstance(getUsername(), getPassword()); setConnection(twitter); }
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
/** * Return the list of followers names./* w ww .j av a 2 s . c o m*/ */ public List<String> getFollowers() { List<String> followers = new ArrayList<String>(); try { long[] ids = getConnection().getFollowersIDs(-1).getIDs(); if (ids.length == 0) { return followers; } int index = 0; while (ids.length > index) { long[] lookup = ids; if (index > 0) { lookup = Arrays.copyOfRange(ids, index, Math.min(ids.length, index + MAX_LOOKUP)); } else if (ids.length > MAX_LOOKUP) { lookup = Arrays.copyOf(ids, MAX_LOOKUP); } index = index + MAX_LOOKUP; ResponseList<User> users = getConnection().lookupUsers(lookup); for (User user : users) { followers.add(user.getScreenName()); } // Only return first 100. break; } } catch (Exception exception) { log(exception); } return followers; }
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
/** * Return the list of friends names./*from w ww. ja v a 2 s . com*/ */ public List<String> getFriends() { List<String> friends = new ArrayList<String>(); try { long[] friendIds = getConnection().getFriendsIDs(-1).getIDs(); int index = 0; while (friendIds.length > index) { long[] lookup = friendIds; if (index > 0) { lookup = Arrays.copyOfRange(friendIds, index, Math.min(friendIds.length, index + MAX_LOOKUP)); } else if (friendIds.length > MAX_LOOKUP) { lookup = Arrays.copyOf(friendIds, MAX_LOOKUP); } index = index + MAX_LOOKUP; ResponseList<User> users = getConnection().lookupUsers(lookup); for (User user : users) { friends.add(user.getScreenName()); } // Only return first 100. break; } } catch (Exception exception) { log(exception); } return friends; }
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
public boolean checkFriendship(long friendId, boolean welcomeOnly) throws TwitterException { long[] lookup = new long[1]; lookup[0] = friendId;//www . ja v a 2 s . c o m ResponseList<User> users = getConnection().lookupUsers(lookup); User friend = users.get(0); if (friend.getScreenName().equals(getUserName())) { return false; } if (!getAutoFollowKeywords().isEmpty()) { StringWriter writer = new StringWriter(); writer.write(friend.getScreenName().toLowerCase()); writer.write(" "); writer.write(friend.getDescription().toLowerCase()); writer.write(" "); writer.write(friend.getLocation().toLowerCase()); writer.write(" "); writer.write(friend.getLang().toLowerCase()); writer.write(" "); writer.write(friend.getName().toLowerCase()); boolean match = false; for (String text : getAutoFollowKeywords()) { List<String> keywords = new TextStream(text.toLowerCase()).allWords(); if (new TextStream(writer.toString()).allWords().containsAll(keywords)) { match = true; break; } } if (!match) { log("Autofollow skipping friend, does not match keywords", Level.FINE, friend.getScreenName()); return false; } } Network memory = getBot().memory().newMemory(); Vertex speaker = memory.createSpeaker(friend.getScreenName()); speaker.setPinned(true); // Only try to follow a user once. if (!speaker.hasRelationship(Primitive.FOLLOWED)) { speaker.addRelationship(Primitive.FOLLOWED, memory.createTimestamp()); memory.save(); if (!welcomeOnly && getAutoFollow()) { log("Adding autofollow friend.", Level.INFO, friend.getScreenName()); getConnection().createFriendship(friendId); Utils.sleep(1000); } if (!getWelcomeMessage().isEmpty()) { log("Sending welcome message.", Level.INFO, friend.getScreenName()); sendMessage(getWelcomeMessage(), friend.getScreenName()); Utils.sleep(1000); } if (welcomeOnly) { return false; } return true; } log("Autofollow skipping friend, already followed once", Level.FINE, friend.getScreenName()); return false; }
From source file:org.encuestame.social.api.templates.TwitterAPITemplate.java
License:Apache License
@Override public SocialUserProfile getProfile() throws Exception { final SocialUserProfile profile = new SocialUserProfile(); User user = this.getUser(); profile.setId(String.valueOf(user.getId())); profile.setCreatedAt(user.getCreatedAt()); profile.setProfileUrl("http://www.twitter.com/" + user.getScreenName()); profile.setName(user.getName());//from w ww. ja va 2 s .co m profile.setScreenName(user.getScreenName()); profile.setUsername(user.getScreenName()); profile.setProfileImageUrl(user.getProfileImageURL().toString()); profile.setDescription(user.getDescription()); profile.setCreatedAt(user.getCreatedAt()); profile.setLocation(user.getLocation()); return profile; }
From source file:org.examproject.tweet.service.SimpleTweetService.java
License:Apache License
private ProfileDto getUserProfile(String username) { try {//from www. j a va 2 s . co m Twitter twitter = getTwitter(); User user = twitter.showUser(username); ProfileDto profileDto = new ProfileDto(); profileDto.setScreenName(user.getScreenName()); profileDto.setImageURL(user.getProfileImageURL().toString()); profileDto.setDescription(user.getDescription()); return profileDto; } catch (TwitterException te) { throw new RuntimeException(te); } }
From source file:org.getlantern.firetweet.model.ParcelableDirectMessage.java
License:Open Source License
public ParcelableDirectMessage(final DirectMessage message, final long account_id, final boolean is_outgoing) { this.account_id = account_id; this.is_outgoing = is_outgoing; final User sender = message.getSender(), recipient = message.getRecipient(); final String sender_profile_image_url = sender != null ? sender.getProfileImageUrlHttps() : null; final String recipient_profile_image_url = recipient != null ? recipient.getProfileImageUrlHttps() : null; id = message.getId();//www . j a v a 2s . c o m timestamp = getTime(message.getCreatedAt()); sender_id = sender != null ? sender.getId() : -1; recipient_id = recipient != null ? recipient.getId() : -1; text_html = TwitterContentUtils.formatDirectMessageText(message); text_plain = message.getText(); sender_name = sender != null ? sender.getName() : null; recipient_name = recipient != null ? recipient.getName() : null; sender_screen_name = sender != null ? sender.getScreenName() : null; recipient_screen_name = recipient != null ? recipient.getScreenName() : null; this.sender_profile_image_url = sender_profile_image_url; this.recipient_profile_image_url = recipient_profile_image_url; text_unescaped = toPlainText(text_html); media = ParcelableMedia.fromEntities(message); }
From source file:org.getlantern.firetweet.model.ParcelableStatus.java
License:Open Source License
public ParcelableStatus(final Status orig, final long account_id, final boolean is_gap) { this.is_gap = is_gap; this.account_id = account_id; id = orig.getId();/*from www . j ava 2 s . co m*/ timestamp = getTime(orig.getCreatedAt()); final Status retweeted = orig.getRetweetedStatus(); final User retweet_user = retweeted != null ? orig.getUser() : null; is_retweet = orig.isRetweet(); retweet_id = retweeted != null ? retweeted.getId() : -1; retweet_timestamp = retweeted != null ? getTime(retweeted.getCreatedAt()) : -1; retweeted_by_id = retweet_user != null ? retweet_user.getId() : -1; retweeted_by_name = retweet_user != null ? retweet_user.getName() : null; retweeted_by_screen_name = retweet_user != null ? retweet_user.getScreenName() : null; retweeted_by_profile_image = retweet_user != null ? retweet_user.getProfileImageUrlHttps() : null; final Status quoted = orig.getQuotedStatus(); final User quote_user = quoted != null ? orig.getUser() : null; is_quote = orig.isQuote(); quote_id = quoted != null ? quoted.getId() : -1; quote_text_html = TwitterContentUtils.formatStatusText(orig); quote_text_plain = orig.getText(); quote_text_unescaped = HtmlEscapeHelper.toPlainText(quote_text_html); quote_timestamp = orig.getCreatedAt().getTime(); quote_source = orig.getSource(); quoted_by_user_id = quote_user != null ? quote_user.getId() : -1; quoted_by_user_name = quote_user != null ? quote_user.getName() : null; quoted_by_user_screen_name = quote_user != null ? quote_user.getScreenName() : null; quoted_by_user_profile_image = quote_user != null ? quote_user.getProfileImageUrlHttps() : null; quoted_by_user_is_protected = quote_user != null && quote_user.isProtected(); quoted_by_user_is_verified = quote_user != null && quote_user.isVerified(); final Status status; if (quoted != null) { status = quoted; } else if (retweeted != null) { status = retweeted; } else { status = orig; } final User user = status.getUser(); user_id = user.getId(); user_name = user.getName(); user_screen_name = user.getScreenName(); user_profile_image_url = user.getProfileImageUrlHttps(); user_is_protected = user.isProtected(); user_is_verified = user.isVerified(); user_is_following = user.isFollowing(); text_html = TwitterContentUtils.formatStatusText(status); media = ParcelableMedia.fromEntities(status); text_plain = status.getText(); retweet_count = status.getRetweetCount(); favorite_count = status.getFavoriteCount(); reply_count = status.getReplyCount(); descendent_reply_count = status.getDescendentReplyCount(); in_reply_to_name = TwitterContentUtils.getInReplyToName(status); in_reply_to_screen_name = status.getInReplyToScreenName(); in_reply_to_status_id = status.getInReplyToStatusId(); in_reply_to_user_id = status.getInReplyToUserId(); source = status.getSource(); location = ParcelableLocation.fromGeoLocation(status.getGeoLocation()); is_favorite = status.isFavorited(); text_unescaped = HtmlEscapeHelper.toPlainText(text_html); my_retweet_id = retweeted_by_id == account_id ? id : status.getCurrentUserRetweet(); is_possibly_sensitive = status.isPossiblySensitive(); mentions = ParcelableUserMention.fromUserMentionEntities(status.getUserMentionEntities()); card = ParcelableCardEntity.fromCardEntity(status.getCard(), account_id); place_full_name = getPlaceFullName(status.getPlace()); card_name = card != null ? card.name : null; }
From source file:org.getlantern.firetweet.model.ParcelableUser.java
License:Open Source License
public ParcelableUser(final User user, final long account_id, final long position) { this.position = position; this.account_id = account_id; final URLEntity[] urls_url_entities = user.getURLEntities(); id = user.getId();//from w ww . j av a2s . com created_at = user.getCreatedAt().getTime(); is_protected = user.isProtected(); is_verified = user.isVerified(); name = user.getName(); screen_name = user.getScreenName(); description_plain = user.getDescription(); description_html = TwitterContentUtils.formatUserDescription(user); description_expanded = TwitterContentUtils.formatExpandedUserDescription(user); description_unescaped = HtmlEscapeHelper.toPlainText(description_html); location = user.getLocation(); profile_image_url = user.getProfileImageUrlHttps(); profile_banner_url = user.getProfileBannerImageUrl(); url = user.getURL(); url_expanded = url != null && urls_url_entities != null && urls_url_entities.length > 0 ? urls_url_entities[0].getExpandedURL() : null; is_follow_request_sent = user.isFollowRequestSent(); followers_count = user.getFollowersCount(); friends_count = user.getFriendsCount(); statuses_count = user.getStatusesCount(); favorites_count = user.getFavouritesCount(); listed_count = user.getListedCount(); is_following = user.isFollowing(); background_color = ParseUtils.parseColor("#" + user.getProfileBackgroundColor(), 0); link_color = ParseUtils.parseColor("#" + user.getProfileLinkColor(), 0); text_color = ParseUtils.parseColor("#" + user.getProfileTextColor(), 0); is_cache = false; is_basic = false; }
From source file:org.getlantern.firetweet.model.ParcelableUserList.java
License:Open Source License
public ParcelableUserList(final UserList list, final long account_id, final long position, final boolean is_following) { final User user = list.getUser(); this.position = position; this.account_id = account_id; id = list.getId();/*w w w . j a v a 2 s .c o m*/ is_public = list.isPublic(); this.is_following = is_following; name = list.getName(); description = list.getDescription(); user_id = user.getId(); user_name = user.getName(); user_screen_name = user.getScreenName(); user_profile_image_url = user.getProfileImageUrlHttps(); members_count = list.getMemberCount(); subscribers_count = list.getSubscriberCount(); }