Example usage for twitter4j User getFriendsCount

List of usage examples for twitter4j User getFriendsCount

Introduction

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

Prototype

int getFriendsCount();

Source Link

Document

Returns the number of users the user follows (AKA "followings")

Usage

From source file:MainActivity.java

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

    twitter = t;/*from  w w w. ja  v  a 2 s .c om*/
    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 . ja  v  a 2s .  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();//from www .j a v a  2 s  .  c om
    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 w  w  . ja v a2 s  .  c o m
 * @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.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 {/*www  . j  av  a2s  .  c o  m*/

        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  
 * /*from   w  ww  .  java  2 s.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.dwdesign.tweetings.fragment.UserProfileFragment.java

License:Open Source License

public void changeUser(final long account_id, final User user) {
    mFriendship = null;// w w  w. j  a v a 2s . 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();
}

From source file:com.eventattend.portal.bl.TwitterBL.java

License:Open Source License

public TwitterDTO fetchProfile(User user, TwitterDTO twitterDTO) {
    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    String userDesc = null;//from   w w w . jav  a2 s.c  om
    String favCount = null;
    String followCount = null;
    String friendsCount = null;
    String location = null;
    String name = null;
    String profImgUrl = null;
    String personalUrl = null;
    String twitterURL = "http://twitter.com/" + user.getScreenName();
    userDesc = user.getDescription();
    favCount = String.valueOf(user.getFavouritesCount());
    followCount = String.valueOf(user.getFollowersCount());
    friendsCount = String.valueOf(user.getFriendsCount());
    location = user.getLocation();
    name = user.getName();
    profImgUrl = String.valueOf(user.getProfileImageURL());
    //   System.out.println("User ID   >>  "+user.getId());
    //System.out.println("TwitterA/C CreatedAt  >>  "+user.getCreatedAt());
    System.out.println("Description   >>  " + user.getDescription());
    System.out.println("FavouritesCount   >>  " + user.getFavouritesCount());
    System.out.println("FollowersCoun   >>  " + user.getFollowersCount());
    System.out.println("FriendsCount   >>  " + user.getFriendsCount());
    System.out.println("Language   >>  " + user.getLang());
    System.out.println("Location >>  " + user.getLocation());
    System.out.println("Name  >>  " + user.getName());
    System.out.println("ProfileImageURL   >>  " + user.getProfileImageURL());
    System.out.println("Total tweets   >>  " + user.getStatusesCount());

    if (twitterURL != null) {
        twitterDTO.setUserURL(twitterURL);
        System.out.println("Twitter URL   >>  " + twitterURL);
    }
    if (userDesc != null && (!userDesc.equals(""))) {
        twitterDTO.setUserDesc(userDesc);
    } else {
        twitterDTO.setUserDesc(null);
    }
    if (favCount != null) {
        twitterDTO.setUserFavCount(favCount);
    }
    if (followCount != null) {
        twitterDTO.setFollowersCount(followCount);
    }
    if (friendsCount != null) {

        twitterDTO.setFriendsCount(friendsCount);
    }
    if (location != null) {
        twitterDTO.setUserLocation(location);
    }
    if (name != null) {
        twitterDTO.setUserName(name);
    }
    if (profImgUrl != null) {
        twitterDTO.setUserImg(profImgUrl);
    }
    if (user.getURL() != null) {
        if (!user.getURL().equals(twitterURL)) {
            personalUrl = String.valueOf(user.getURL());
            System.out.println("Personal URL   >>  " + user.getURL());
            twitterDTO.setPersonalUrl(personalUrl);
        }
    }
    //   Status status=user.getStatus();
    //   System.out.println("Latest Tweet  >> TweetId "+status.getId()+"|Tweet> "+status.getText()+" |via> "+status.getSource()
    //         +"|Loc >"+status.getGeoLocation()+"|tweetTime >"+status.getCreatedAt()+"Place Details we can get >"+status.getPlace());         
    /*System.out.println("RateLimitStatus   >>  "+user.getRateLimitStatus());
    System.out.println("ProfileBackgroundColor   >>  "+user.getProfileBackgroundColor());
    System.out.println("ProfileBackgroundImageUrl   >>  "+user.getProfileBackgroundImageUrl());
    System.out.println("ProfileLinkColor   >>  "+user.getProfileLinkColor());
    System.out.println("ProfileSidebarBorderColor   >>  "+user.getProfileSidebarBorderColor());
    System.out.println("user.getProfileSidebarFillColor()   >>  "+user.getProfileSidebarFillColor());
    System.out.println("ProfileTextColor   >>  "+user.getProfileTextColor());*/
    return twitterDTO;
}

From source file:com.freshdigitable.udonroad.module.realm.UserRealm.java

License:Apache License

UserRealm(final User user) {
    this.id = user.getId();
    this.profileImageURLHttps = user.getProfileImageURLHttps();
    this.miniProfileImageURLHttps = user.getMiniProfileImageURLHttps();
    this.name = user.getName();
    this.screenName = user.getScreenName();
    this.description = user.getDescription();
    this.profileBannerMobileURL = user.getProfileBannerMobileURL();
    this.statusesCount = user.getStatusesCount();
    this.followersCount = user.getFollowersCount();
    this.friendsCount = user.getFriendsCount();
    this.favoritesCount = user.getFavouritesCount();
    this.profileLinkColor = user.getProfileLinkColor();
    this.descriptionURLEntities = URLEntityRealm.createList(user.getDescriptionURLEntities());
    this.url = user.getURL();
    if (user.getURLEntity() != null) {
        this.urlEntity = new URLEntityRealm(user.getURLEntity());
    }//w w w . j a  va  2s .c om
    this.location = user.getLocation();
    this.verified = user.isVerified();
    this.isProtected = user.isProtected();
}