1

twitter4j v2.2.6 のストリーミング API を使用していますが、フィルタリングに問題があります。サンプル ストリームは問題なく取得できますが、地理位置情報フィルターを追加しようとすると、ストリーム出力は変化しません (地理位置情報なしで geoloc を含むツイートをまだ取得していますが、バウンディング ボックスの外側にあります)。これが私のコードの一部です:

private static FilterQuery getBoundingBoxFilter() {
    // New Delhi India
    double lat = 28.6;
    double lon = 77.2;
    double lon1 = lon - .5;
    double lon2 = lon + .5;
    double lat1 = lat - .5;
    double lat2 = lat + .5;

    double bbox[][] = {{lon1, lat1}, {lon2, lat2}};        
    FilterQuery filtro = new FilterQuery();
    return filtro.locations(bbox);        
}

public static void streamIt() {
    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    FilterQuery fq = getBoundingBoxFilter();
    StatusListener listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {
            GeoLocation gl = status.getGeoLocation();
            StringBuilder msg = new StringBuilder();
            if (gl != null) {
                msg.append("Lat/Lon: ").append(gl.getLatitude()).append(",").append(gl.getLongitude()).append(" - ");
                msg.append(status.getText());
                LOG.info(msg.toString());
            } else {
              msg.append(status.getText());
              LOG.info(msg.toString());
            }
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @Override
        public void onException(Exception ex) {
            if (!(ex instanceof IllegalStateException)) {
                ex.printStackTrace();
            }
        }

        @Override
        public void onStallWarning(StallWarning sw) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    };
    twitterStream.addListener(listener);
    if (fq != null) {
        twitterStream.filter(fq);
    }        
    twitterStream.sample();        
}

それで、私は何を間違っていますか?何か案は?

よろしく、

ティム

4

1 に答える 1

1

次の行を削除して、やり直してください。

twitterStream.sample();   
于 2013-03-14T20:43:19.693 に答える