Example usage for twitter4j Twitter getFollowersIDs

List of usage examples for twitter4j Twitter getFollowersIDs

Introduction

In this page you can find the example usage for twitter4j Twitter getFollowersIDs.

Prototype

IDs getFollowersIDs(long cursor) throws TwitterException;

Source Link

Document

Returns an array of numeric IDs for every user the specified user is followed by.

Usage

From source file:com.arihant15.ActionServlet.java

@RequestMapping("/getFriends.arihant15")
public void doFriends(HttpServletRequest req, HttpServletResponse res) throws IOException {
    try {//w ww  .  ja v a2  s.  c o m
        Twitter twitter = (Twitter) req.getSession().getAttribute("t");
        IDs ids = twitter.getFollowersIDs(-1);
        PagableResponseList<User> users;
        for (long id : ids.getIDs()) {
            (res.getWriter()).println("@" + twitter.showUser(id).getName() + "\n");
        }
    } catch (Exception e) {
        (res.getWriter()).println(e);
    }
}

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

License:Open Source License

private List getFollowersProfile(Twitter twitterClient, String screenName, TwitterDTO twitterDTO)
        throws BaseAppException {
    //ProfileDTO profileDTO = null;
    User profile = null;/*  ww  w  . j  a va2 s . com*/
    List followersList = null;

    try {
        followersList = new ArrayList();
        int i = 0;
        IDs friendsIds = twitterClient.getFollowersIDs(screenName);

        if (friendsIds != null) {
            for (int userId : friendsIds.getIDs()) {
                //if(i<5){
                profile = twitterClient.showUser(userId);

                twitterDTO = fetchProfile(profile, twitterDTO);
                followersList.add(twitterDTO);
            }
            //i++;

            //}
        }

    } catch (TwitterException e) {

        processTwitterException(e);
    }

    return followersList;
}

From source file:com.gmail.altakey.joanne.service.TwitterAuthService.java

License:Apache License

public static void updateRelations(final Context context, final AccessToken token) {
    final SharedPreferences prefs = context.getSharedPreferences(PREFERENCE, MODE_PRIVATE);
    try {/*ww  w .j av  a 2  s .c  o  m*/
        final Twitter twitter = TwitterFactory.getSingleton();
        twitter.setOAuthAccessToken(token);

        final Set<Long> friends = new HashSet<Long>();
        for (IDs ids = twitter.getFriendsIDs(-1);; ids = twitter.getFriendsIDs(ids.getNextCursor())) {
            for (Long id : ids.getIDs()) {
                friends.add(id);
            }
            if (!ids.hasNext()) {
                break;
            }
        }

        final Set<Long> followers = new HashSet<Long>();
        for (IDs ids = twitter.getFollowersIDs(-1);; ids = twitter.getFollowersIDs(ids.getNextCursor())) {
            for (Long id : ids.getIDs()) {
                followers.add(id);
            }
            if (!ids.hasNext()) {
                break;
            }
        }

        prefs.edit().putString(KEY_FRIENDS, new IdListCoder().encode(friends))
                .putString(KEY_FOLLOWERS, new IdListCoder().encode(followers)).commit();
        UserRelation.notifyRelationsChanged();
        Log.d(TAG, String.format("got %d friends", friends.size()));
        Log.d(TAG, String.format("got %d followers", followers.size()));
    } catch (TwitterException e) {
        Log.w(TAG, "cannot get follower list", e);
    }
}

From source file:it.greenvulcano.gvesb.social.twitter.directcall.TwitterOperationGetFollowersIDs.java

License:Open Source License

@Override
public void execute(SocialAdapterAccount account) throws SocialAdapterException {
    try {/*from  w  w w  . j  a  v a 2  s.  c o  m*/
        Twitter twitter = (Twitter) account.getProxyObject();
        if ((followingId == null) || "".equals(followingId)) {
            ids = twitter.getFollowersIDs(Long.parseLong(cursor));
        } else {
            try {
                long id = Long.parseLong(followingId);
                ids = twitter.getFollowersIDs(id, Long.parseLong(cursor));
            } catch (NumberFormatException exc) {
                ids = twitter.getFollowersIDs(followingId, Long.parseLong(cursor));
            }
        }
    } catch (NumberFormatException exc) {
        logger.error("Call to TwitterOperationGetFollowersIDs failed. Check followingId[" + followingId
                + "] and cursor[" + cursor + "] format.", exc);
        throw new SocialAdapterException("Call to TwitterOperationGetFollowersIDs failed. Check followingId["
                + followingId + "] and cursor[" + cursor + "] format.", exc);
    } catch (TwitterException exc) {
        logger.error("Call to TwitterOperationGetFollowersIDs followingId[" + followingId + "] and cursor["
                + cursor + "] failed.", exc);
        throw new SocialAdapterException("Call to TwitterOperationGetFollowersIDs followingId[" + followingId
                + "] and cursor[" + cursor + "] failed.", exc);
    }
}

From source file:org.rhq.plugins.twitter.TwitterComponent.java

License:Open Source License

/**
 * Gather measurement data//from  ww w .ja v  a2s . c  om
 *  @see org.rhq.core.pluginapi.measurement.MeasurementFacet#getValues(org.rhq.core.domain.measurement.MeasurementReport, java.util.Set)
 */
public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception {

    Twitter twitter = createTwitterInstance();

    for (MeasurementScheduleRequest req : metrics) {
        if (req.getName().equals("tweetCount")) {

            //             Twitter twitter = new Twitter(username,password,serverUrl);
            Paging paging = new Paging();
            if (lastId == NOT_YET_SET) {
                paging.setSinceId(1);
                paging.setCount(1);
            } else {
                paging.setSinceId(lastId);
                paging.setCount(100);
            }
            List<Status> statuses;
            statuses = twitter.getHomeTimeline(paging);
            if (lastId > 0) {
                MeasurementDataNumeric res;
                res = new MeasurementDataNumeric(req, (double) statuses.size());

                eventPoller.addStatuses(statuses);
                report.addData(res);
            }
            if (statuses.size() > 0)
                lastId = statuses.get(0).getId(); // This is always newest first
        } else if (req.getName().equals("followerCount")) {
            int count = twitter.getFollowersIDs(-1).getIDs().length;
            MeasurementDataNumeric res;
            res = new MeasurementDataNumeric(req, (double) count);
            report.addData(res);
        }
    }
}