Example usage for twitter4j User getScreenName

List of usage examples for twitter4j User getScreenName

Introduction

In this page you can find the example usage for twitter4j User getScreenName.

Prototype

String getScreenName();

Source Link

Document

Returns the screen name of the user

Usage

From source file:com.appspot.bitlyminous.service.impl.TwitterServiceImpl.java

License:Apache License

public void sendUrlStatistics() {
    try {// w w  w.  j a  v  a  2 s.  c o m
        Twitter twitter = getTwitterClient();
        UserService userService = ServiceFactory.newInstance().createUserService();
        for (User user : twitter.getFriendsStatuses()) {
            com.appspot.bitlyminous.entity.User entity = userService.getUserByScreenName(user.getScreenName());
            List<Url> urls = entity.getUrls();
            twitter.sendDirectMessage(user.getId(), buildUrlStatisticsStatus(urls));
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}

From source file:com.appspot.bitlyminous.service.impl.TwitterServiceImpl.java

License:Apache License

public void sendFollowFridays() {
    try {//ww  w  .ja va2s .  c om
        Twitter twitter = getTwitterClient();
        UserService userService = ServiceFactory.newInstance().createUserService();
        for (User user : twitter.getFriendsStatuses()) {
            com.appspot.bitlyminous.entity.User entity = userService.getUserByScreenName(user.getScreenName());
            List<com.appspot.bitlyminous.entity.User> similarUsers = userService.getSimilarUsers(entity, 5);
            if (!similarUsers.isEmpty()) {
                twitter.updateStatus(buildFollowFridayStatus(entity, similarUsers));
            }
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}

From source file:com.appspot.bitlyminous.service.impl.TwitterServiceImpl.java

License:Apache License

public void sendPopularLinks() {
    try {/*from w  w  w  .  j a va2s  .  c om*/
        Twitter twitter = getTwitterClient();
        UserService userService = ServiceFactory.newInstance().createUserService();
        for (User user : twitter.getFriendsStatuses()) {
            com.appspot.bitlyminous.entity.User entity = userService.getUserByScreenName(user.getScreenName());
            // TODO-NM: Find popular links based on user tags.
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}

From source file:com.appspot.bitlyminous.service.impl.TwitterServiceImpl.java

License:Apache License

public void importFriends() {
    try {//w  w  w  .  j a v  a2  s .c  o  m
        Twitter twitter = getTwitterClient();
        UserService userService = ServiceFactory.newInstance().createUserService();
        boolean exists = true;
        long cursor = -1;

        while (exists) {
            //return 100 follower with status per request
            PagableResponseList<User> twitterFollowers = twitter.getFollowersStatuses(cursor);

            for (User user : twitterFollowers) {
                com.appspot.bitlyminous.entity.User entity = userService
                        .getUserByScreenName(user.getScreenName());
                if (entity == null) {
                    entity = new com.appspot.bitlyminous.entity.User();
                    entity.setScreenName(user.getScreenName());
                    entity.setLevel(com.appspot.bitlyminous.entity.User.Level.DIRECT_USER);
                    userService.updateUser(entity);
                    twitter.createFriendship(user.getScreenName());
                    twitter.sendDirectMessage(user.getScreenName(),
                            ApplicationResources.getLocalizedString("com.appspot.bitlyminous.message.welcome"));
                    // following fofs will hit the limit soon.
                    //                   IDs friendsIDs = twitter.getFriendsIDs(user.getId());
                    //                   for (int id : friendsIDs.getIDs()) {
                    //                      twitter.createFriendship(id);
                    //                   }
                } else if (entity.getLevel() != com.appspot.bitlyminous.entity.User.Level.DIRECT_USER) {
                    entity.setLevel(com.appspot.bitlyminous.entity.User.Level.DIRECT_USER);
                    userService.updateUser(entity);
                    twitter.createFriendship(user.getScreenName());
                    twitter.sendDirectMessage(user.getScreenName(),
                            ApplicationResources.getLocalizedString("com.appspot.bitlyminous.message.welcome"));
                    // following fofs will hit the limit soon.
                    //                   IDs friendsIDs = twitter.getFriendsIDs(user.getId());
                    //                   for (int id : friendsIDs.getIDs()) {
                    //                      twitter.createFriendship(id);
                    //                   }
                }
            }

            exists = twitterFollowers.hasNext();
            cursor = twitterFollowers.getNextCursor();
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}

From source file:com.appspot.bitlyminous.service.impl.TwitterServiceImpl.java

License:Apache License

/**
 * Builds the follow friday status./*from  w  ww  .  j a va 2 s  .  co m*/
 * 
 * @param user the user
 * @param similarUsers the similar users
 * 
 * @return the string
 */
private String buildFollowFridayStatus(com.appspot.bitlyminous.entity.User user,
        List<com.appspot.bitlyminous.entity.User> similarUsers) {
    StringBuilder builder = new StringBuilder();
    builder.append("@");
    builder.append(user.getScreenName());
    for (com.appspot.bitlyminous.entity.User similarUser : similarUsers) {
        builder.append(" @");
        builder.append(similarUser.getScreenName());
    }
    return builder.toString();
}

From source file:com.aremaitch.codestock2010.library.TwitterLib.java

License:Apache License

public HashMap<String, Long> getUserIDsFromScreenNames(List<String> screenNames) throws TwitterException {
    HashMap<String, Long> result = new HashMap<String, Long>();

    //  Talk about awkward syntax:
    ResponseList<User> users = t.lookupUsers(screenNames.toArray(new String[screenNames.size()]));
    if (users.size() > 0) {
        for (User u : users) {
            result.put(u.getScreenName(), u.getId());
        }//from w w  w.java 2s  .  c o m
    }
    return result;
}

From source file:com.avishkar.NewGetFollowersIDs.java

License:Apache License

private static List<Long> getUserFollwers(long twitterUserId)
        throws UnknownHostException, TwitterException, InterruptedException {
    Twitter twitter = new TwitterFactory(AccessTokenUtil.getConfig()).getInstance();
    List<Long> filteredUserListOnFollowerCount = new ArrayList<Long>();
    final Gson gson = new Gson();
    try {/*from   w  ww .  j  av a 2s .c  om*/

        checkRateLimit("/followers/ids", twitter);
        System.out.println("Listing followers's Follower for ID:" + twitterUserId + System.lineSeparator());
        IDs followerIDs = twitter.getFollowersIDs(twitterUserId, -1);
        JsonObject followerJSON = new JsonObject();

        followerJSON.addProperty("id", twitterUserId);
        followerJSON.addProperty("followers", gson.toJson(followerIDs.getIDs()));
        DBAccess.insert(gson.toJson(followerJSON));

        System.out.println("Current Followers Fetched Size:" + followerIDs.getIDs().length);
        // Filtering for influential user
        if (followerIDs.getIDs().length > 1000) {
            System.out.println("User assumed as Influential");
            return null;
        }
        int from = 0;
        int to = 99;
        int limit = checkRateLimit("/users/lookup", twitter);
        while (from < followerIDs.getIDs().length) {
            if (to > followerIDs.getIDs().length)
                to = followerIDs.getIDs().length - 1;
            if (limit == 0)
                checkRateLimit("/users/lookup", twitter);
            ResponseList<User> followers = twitter
                    .lookupUsers(Arrays.copyOfRange(followerIDs.getIDs(), from, to));
            System.out.println("Recieved User count:" + followers.size());
            for (User user : followers) {
                DBAccess.insertUser(gson.toJson(user));
                if (user.getFollowersCount() < 1000) {
                    // if(user.getStatusesCount()>0 &&
                    // user.getStatus()!=null &&
                    // sevenDaysAgo.after(user.getStatus().getCreatedAt()))
                    filteredUserListOnFollowerCount.add(user.getId());
                    getStatuses(user.getScreenName(), twitter);
                } else
                    System.out.println("User " + user.getScreenName()
                            + " is pruned for Influential or over subscription." + " Follower count:"
                            + user.getFollowersCount() + " Friends Count:" + user.getFriendsCount());
            }

            from += 100;
            to += 100;
            limit--;
        }
    } catch (TwitterException te) {
        if (te.getStatusCode() == HttpResponseCode.UNAUTHORIZED
                || te.getStatusCode() == HttpResponseCode.NOT_FOUND) {
            System.out.println("Encountered locked profile. Skipping " + twitterUserId);
            return null;

            // log something here
        }
        te.printStackTrace();
        System.out.println("Failed to get followers' Follower: " + te.getMessage());
        // System.exit(-1);
    }

    return filteredUserListOnFollowerCount;
}

From source file:com.daemon.database.Transactor.java

License:Open Source License

/**
 * Creates an error message with user information for further analysis.
 * @param user The user whose information is to be represented.
 * @return The error message.//from w ww.  jav a2 s .c  o  m
 */
private String getUserErrorString(User user) {
    StringBuffer sb = new StringBuffer();

    sb.append("User information:\n");
    sb.append("  id: " + user.getId() + "\n");
    sb.append("  screen name: " + user.getScreenName() + "\n");
    sb.append("  name: " + user.getName() + "\n");
    sb.append("  description: " + user.getDescription() + "\n");
    sb.append("    length: " + user.getDescription().length() + "\n");
    sb.append("   elength: " + StringUtil.escapeNonAscii(user.getDescription()).length() + "\n");
    sb.append("  language: " + user.getLang() + "\n");
    sb.append("  location: " + user.getLocation());

    return sb.toString();
}

From source file:com.daemon.database.Transactor.java

License:Open Source License

/**
 * Adds only the given User to the SQL.Batch which will be saved
 *  in the DB by savedAllTweetsTransactionsafe  
 * /*from ww w  .j a va  2s  .c  o  m*/
 * @param user The user to be saved.
 * @throws SQLException
 */
private void saveUser(User user) throws SQLException {
    prepStatementUser.setLong(1, user.getId());
    prepStatementUser.setString(2, user.getName());
    prepStatementUser.setString(3, user.getScreenName());
    prepStatementUser.setString(4, user.getProfileImageURL());
    prepStatementUser.setTimestamp(5, new java.sql.Timestamp(user.getCreatedAt().getTime()));
    prepStatementUser.setString(6, user.getLocation());
    prepStatementUser.setString(7, user.getURL());
    prepStatementUser.setString(8, user.getLang());
    prepStatementUser.setInt(9, user.getFollowersCount());
    prepStatementUser.setBoolean(10, user.isVerified());
    prepStatementUser.setString(11, user.getTimeZone());
    prepStatementUser.setString(12, user.getDescription());
    prepStatementUser.setInt(13, user.getStatusesCount());
    prepStatementUser.setInt(14, user.getFriendsCount());

    prepStatementUser.addBatch();
}

From source file:com.daiv.android.twitter.adapters.PeopleArrayAdapter.java

License:Apache License

public void bindView(final View view, int position, final User user) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    final long id = user.getId();
    holder.userId = id;/*from ww  w.  j av a 2s.  c o  m*/

    holder.name.setText(user.getName());
    holder.screenName.setText("@" + user.getScreenName());

    //holder.picture.loadImage(user.getBiggerProfileImageURL(), true, null, NetworkedCacheableImageView.CIRCLE);
    final String url = user.getBiggerProfileImageURL();
    if (settings.roundContactImages) {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (holder.userId == id) {
                    loadCircleImage(context, holder, url, mCache, id);
                }
            }
        }, 500);
    } else {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (holder.userId == id) {
                    loadImage(context, holder, url, mCache, id);
                }
            }
        }, 500);
    }

    if (openFirst && position == 0) {
        holder.background.performClick();
        ((Activity) context).finish();
    }

    setFollowingStatus(holder, user);
}