Example usage for twitter4j Paging setSinceId

List of usage examples for twitter4j Paging setSinceId

Introduction

In this page you can find the example usage for twitter4j Paging setSinceId.

Prototype

public void setSinceId(long sinceId) 

Source Link

Usage

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

License:Open Source License

/**
 * Gather measurement data/* w  ww  .  j a  v  a2 s .  co  m*/
 *  @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);
        }
    }
}

From source file:org.tweetalib.android.TwitterPaging.java

License:Apache License

public Paging getT4JPaging() {
    Paging result = new Paging();
    if (mMaxId == null && mSinceId == null) {

        if (mPage != null) {
            result.setPage(mPage);//from   w  w w .j  a  va  2 s. co m
        } else {
            result.setPage(1);
        }
    } else {
        if (mMaxId != null) {
            if (mMaxId.longValue() >= 0) {
                result.setMaxId(mMaxId);
            } else {
                Log.d("ERROR", "mMaxId is " + mMaxId.longValue() + ", must be >= 0");
            }
        }
        if (mSinceId != null) {
            if (mSinceId.longValue() >= 0) {
                result.setSinceId(mSinceId);
            } else {
                Log.d("ERROR", "mSinceId is " + mSinceId.longValue() + ", must be >= 0");
            }
        }
    }

    if (mCount != null) {
        result.setCount(mCount);
    } else {
        result.setCount(DEFAULT_STATUS_COUNT);
    }

    return result;
}