Example usage for twitter4j User getFollowersCount

List of usage examples for twitter4j User getFollowersCount

Introduction

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

Prototype

int getFollowersCount();

Source Link

Document

Returns the number of followers

Usage

From source file:MainActivity.java

public void setTwitter(Twitter t) throws TwitterException, MalformedURLException, IOException {

    twitter = t;//from  w w  w.j  a  v  a 2s.  c o  m
    screenName = twitter.getScreenName();
    name.setText(twitter.getScreenName());

    twitter4j.User user = twitter.showUser(twitter.getId());
    URL url = new URL(user.getBiggerProfileImageURL());
    //URL url = new URL(fullUrlPath);
    BufferedImage img = ImageIO.read(url);
    ImageIcon icon = new ImageIcon(img);
    imgIcon.setIcon(icon);
    //JOptionPane.showMessageDialog(null, icon);
    Afollowing.setText(user.getFriendsCount() + "");
    Afollowers.setText(user.getFollowersCount() + "");
    createdAt.setText(user.getCreatedAt() + "");
    lists.setText(user.getListedCount() + "");
    favourites.setText(user.getFavouritesCount() + "");
    tweets.setText(user.getStatusesCount() + "");

}

From source file:aic2013.common.entities.TwitterUser.java

public TwitterUser(User user) {
    id = user.getId();/*from  ww w.j a v  a2  s.  co  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();/*ww  w  .ja v a  2 s  .  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.
 * /*from   w ww  .j  a va  2  s .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: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.amandine.twitterpostforcoucou.Tweet.java

public void getFollowers(String username) {
    Twitter twitterHandle = this.getTwitter();
    long cursor = -1;
    PagableResponseList<User> followers = null;
    //do {/*w  w w.ja v a  2s.c o  m*/
    try {
        followers = twitterHandle.getFollowersList(URLEncoder.encode(username, "UTF-8"), cursor);
    } catch (TwitterException ex) {
        //ex.printStackTrace();
        logger.log(Level.SEVERE, "Cannot get followers", ex.getMessage());
        return;
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(Tweet.class.getName()).log(Level.SEVERE, null, ex);
    }
    for (User follower : followers) {
        // TODO: Collect top 10 followers here
        System.out.println(follower.getName() + " has " + follower.getFollowersCount() + " follower(s)");
    }
    //} while ((cursor = followers.getNextCursor()) != 0);
}

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  a2  s . 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

/**
 * Adds only the given User to the SQL.Batch which will be saved
 *  in the DB by savedAllTweetsTransactionsafe  
 * /*www .j av a  2 s.c  om*/
 * @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.dwdesign.tweetings.fragment.UserProfileFragment.java

License:Open Source License

public void changeUser(final long account_id, final User user) {
    mFriendship = null;//from w  ww.  ja  v  a  2  s .  com
    mUserId = -1;
    mAccountId = -1;
    if (user == null || user.getId() <= 0 || getActivity() == null
            || !isMyActivatedAccount(getActivity(), account_id))
        return;
    if (mUserInfoTask != null && mUserInfoTask.getStatus() == AsyncTask.Status.RUNNING) {
        mUserInfoTask.cancel(true);
    }
    final boolean is_my_activated_account = isMyActivatedAccount(getActivity(), user.getId());
    mUserInfoTask = null;
    mErrorRetryContainer.setVisibility(View.GONE);
    mAccountId = account_id;
    mUserId = user.getId();
    mScreenName = user.getScreenName();

    updateUserColor();
    final boolean is_multiple_account_enabled = getActivatedAccountIds(getActivity()).length > 1;

    mListView.setBackgroundResource(is_multiple_account_enabled ? R.drawable.ic_label_account_nopadding : 0);
    if (is_multiple_account_enabled) {
        final Drawable d = mListView.getBackground();
        if (d != null) {
            d.mutate().setColorFilter(getAccountColor(getActivity(), account_id), PorterDuff.Mode.MULTIPLY);
            mListView.invalidate();
        }
    }

    mNameView.setText(user.getName());
    mScreenNameView.setText("@" + user.getScreenName());
    mScreenNameView.setCompoundDrawablesWithIntrinsicBounds(
            getUserTypeIconRes(user.isVerified(), user.isProtected()), 0, 0, 0);
    final String description = user.getDescription();
    mDescriptionContainer
            .setVisibility(is_my_activated_account || !isNullOrEmpty(description) ? View.VISIBLE : View.GONE);
    mDescriptionContainer.setOnLongClickListener(this);
    mDescriptionView.setText(description);
    final TwidereLinkify linkify = new TwidereLinkify(mDescriptionView);
    linkify.setOnLinkClickListener(this);
    linkify.addAllLinks();
    mDescriptionView.setMovementMethod(LinkMovementMethod.getInstance());
    final String location = user.getLocation();
    mLocationContainer
            .setVisibility(is_my_activated_account || !isNullOrEmpty(location) ? View.VISIBLE : View.GONE);
    mLocationContainer.setOnLongClickListener(this);
    mLocationView.setText(location);
    final String url = user.getURL() != null ? user.getURL().toString() : null;
    mURLContainer.setVisibility(is_my_activated_account || !isNullOrEmpty(url) ? View.VISIBLE : View.GONE);
    mURLContainer.setOnLongClickListener(this);
    mURLView.setText(url);
    mCreatedAtView.setText(formatToLongTimeString(getActivity(), getTimestampFromDate(user.getCreatedAt())));
    mTweetCount.setText(String.valueOf(user.getStatusesCount()));
    mFollowersCount.setText(String.valueOf(user.getFollowersCount()));
    mFriendsCount.setText(String.valueOf(user.getFriendsCount()));
    // final boolean display_profile_image =
    // mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_PROFILE_IMAGE, true);
    // mProfileImageView.setVisibility(display_profile_image ? View.VISIBLE
    // : View.GONE);
    // if (display_profile_image) {
    final String profile_image_url_string = parseString(user.getProfileImageURL());
    final boolean hires_profile_image = getResources().getBoolean(R.bool.hires_profile_image);
    mLazyImageLoader.displayProfileImage(mProfileImageView,
            hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
                    : profile_image_url_string);
    // }

    String profile_banner_url_string = parseString(user.getProfileBannerImageUrl());
    if (profile_banner_url_string != null) {
        final int def_width = getResources().getDisplayMetrics().widthPixels;
        profile_banner_url_string = profile_banner_url_string + "/" + getBestBannerType(def_width);
    }
    final String banner_url = profile_banner_url_string;
    if (mProfileBackgroundView != null) {
        mProfileBackgroundView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        if (banner_url != null) {
            mLazyImageLoader.displayPreviewImage(mProfileBackgroundView, banner_url);
        } else {
            final Drawable d = getResources().getDrawable(R.drawable.linen);
            mProfileBackgroundView.setImageDrawable(d);
        }
    }

    mUser = user;
    if (isMyAccount(getActivity(), user.getId())) {
        final ContentResolver resolver = getContentResolver();
        final ContentValues values = new ContentValues();
        final URL profile_image_url = user.getProfileImageURL();
        if (profile_image_url != null) {
            values.put(Accounts.PROFILE_IMAGE_URL, profile_image_url.toString());
        }
        values.put(Accounts.USERNAME, user.getScreenName());
        final String where = Accounts.USER_ID + " = " + user.getId() + " AND 1 = 1";
        resolver.update(Accounts.CONTENT_URI, values, where, null);
    }
    mAdapter.add(new UserRecentPhotosAction());
    mAdapter.add(new FavoritesAction());
    mAdapter.add(new UserMentionsAction());
    mAdapter.add(new UserListTypesAction());
    if (user.getId() == mAccountId) {
        mAdapter.add(new MyTweetsRetweetedAction());
        mAdapter.add(new SavedSearchesAction());
        boolean nativeMapSupported = true;
        try {
            Class.forName("com.google.android.maps.MapActivity");
            Class.forName("com.google.android.maps.MapView");
        } catch (final ClassNotFoundException e) {
            nativeMapSupported = false;
        }
        if (nativeMapSupported) {
            mAdapter.add(new UserNearbyAction());
        }
        if (user.isProtected()) {
            mAdapter.add(new IncomingFriendshipsAction());
        }
        mAdapter.add(new UserBlocksAction());
    }
    mAdapter.notifyDataSetChanged();

    if (mRecentPhotosGallery != null) {
        mRecentPhotosGallery.setVisibility(View.GONE);
        mRecentPhotosGallery.setAdapter(new ImageAdapter(this.getActivity()));
        mRecentPhotosGallery.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                ParcelableStatus pStatus = mMediaStatuses.get(position);
                final ImageSpec spec = getAllAvailableImage(pStatus.image_orig_url_string);
                if (spec != null) {
                    openImage(UserProfileFragment.this.getActivity(), Uri.parse(spec.full_image_link),
                            pStatus.is_possibly_sensitive);
                }
            }

        });

        mMediaTimelineTask = new MediaTimelineTask(this.getActivity(), mAccountId, mUser.getScreenName());
        if (mMediaTimelineTask != null) {
            mMediaTimelineTask.execute();
        }
    }

    getFriendship();
    checkPushTracked();
}