Package twitter4j

Examples of twitter4j.FilterQuery


      twitterStream.sample();
    }

    else {

      FilterQuery query = new FilterQuery().track(keyWords);
      twitterStream.filter(query);
    }

  }
View Full Code Here


    protected void startStreaming() {
        twitterStream.filter(createFilter(te));
    }

    private FilterQuery createFilter(TwitterEndpoint te) {
        FilterQuery filterQuery = new FilterQuery();
        String allLocationsString = te.getProperties().getLocations();
        if (allLocationsString != null) {
            String[] locationStrings = allLocationsString.split(";");
            double[][] locations = new double[locationStrings.length][2];
            for (int i = 0; i < locationStrings.length; i++) {
                String[] coords = locationStrings[i].split(",");
                locations[i][0] = Double.valueOf(coords[0]);
                locations[i][1] = Double.valueOf(coords[1]);
            }
            filterQuery.locations(locations);
        }

        String keywords = te.getProperties().getKeywords();
        if (keywords != null && keywords.length() > 0) {
            filterQuery.track(keywords.split(","));
        }

        String userIds = te.getProperties().getUserIds();
        if (userIds != null) {
            String[] stringUserIds = userIds.split(",");
            long[] longUserIds = new long[stringUserIds.length];
            for (int i = 0; i < stringUserIds.length; i++) {
                longUserIds[i] = Long.valueOf(stringUserIds[i]);
            }
            filterQuery.follow(longUserIds);
        }

        if (allLocationsString == null && keywords == null && userIds == null) {
            throw new IllegalArgumentException("At least one filter parameter is required");
        }

        filterQuery.setIncludeEntities(true);
        return filterQuery;
    }
View Full Code Here

        super(te);
        twitterStream.filter(createFilter(te));
    }

    private FilterQuery createFilter(TwitterEndpoint te) {
        FilterQuery filterQuery = new FilterQuery();
        String allLocationsString = te.getProperties().getLocations();
        if (allLocationsString != null) {
            String[] locationStrings = allLocationsString.split(";");
            double[][] locations = new double[locationStrings.length][2];
            for (int i = 0; i < locationStrings.length; i++) {
                String[] coords = locationStrings[i].split(",");
                locations[i][0] = Double.valueOf(coords[0]);
                locations[i][1] = Double.valueOf(coords[1]);
            }
            filterQuery.locations(locations);
        }

        String keywords = te.getProperties().getKeywords();
        if (keywords != null && keywords.length() > 0) {
            filterQuery.track(keywords.split(","));
        }
       
        String userIds = te.getProperties().getUserIds();
        if (userIds != null) {
            String[] stringUserIds = userIds.split(",");
            long[] longUserIds = new long[stringUserIds.length];
            for (int i = 0; i < stringUserIds.length; i++) {
                longUserIds[i] = Long.valueOf(stringUserIds[i]);
            }
            filterQuery.follow(longUserIds);
        }
       
        if (allLocationsString == null && keywords == null && userIds == null) {
            throw new IllegalArgumentException("At least one filter parameter is required");
        }

        filterQuery.setIncludeEntities(true);
        return filterQuery;
    }
View Full Code Here

    public void onStallWarning(StallWarning stallWarning) {
        // noop
    }

    private FilterQuery createFilter(TwitterEndpoint te) {
        FilterQuery filterQuery = new FilterQuery();
        String allLocationsString = te.getProperties().getLocations();
        if (allLocationsString != null) {
            String[] locationStrings = allLocationsString.split(";");
            double[][] locations = new double[locationStrings.length][2];
            for (int i = 0; i < locationStrings.length; i++) {
                String[] coords = locationStrings[i].split(",");
                locations[i][0] = Double.valueOf(coords[0]);
                locations[i][1] = Double.valueOf(coords[1]);
            }
            filterQuery.locations(locations);
        }

        String keywords = te.getProperties().getKeywords();
        if (keywords != null && keywords.length() > 0) {
            filterQuery.track(keywords.split(","));
        }

        String userIds = te.getProperties().getUserIds();
        if (userIds != null) {
            String[] stringUserIds = userIds.split(",");
            long[] longUserIds = new long[stringUserIds.length];
            for (int i = 0; i < stringUserIds.length; i++) {
                longUserIds[i] = Long.valueOf(stringUserIds[i]);
            }
            filterQuery.follow(longUserIds);
        }

        if (allLocationsString == null && keywords == null && userIds == null) {
            throw new IllegalArgumentException("At least one filter parameter is required");
        }
View Full Code Here

    /** Number of old tweets to catch before starting to listen live stream */
    int count = 0;

    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    twitterStream.addListener(listener);
    FilterQuery filterQuery = new FilterQuery();
    filterQuery.count(count);
    if (args.length == 0) {
      args = new String[1];
      args[0] = "#twitter";
    }
    filterQuery.track(args);
    twitterStream.filter(filterQuery);
  }
View Full Code Here

            @Override
            public void onScrubGeo(long userId, long upToStatusId) {
            }
        });
        stream.filter(new FilterQuery(0, new long[0], trackArray));
        return stream;
    }
View Full Code Here

            throw new UnsupportedOperationException("gathering of historical tweets is not yet supported in the Twitter4j client");
        }

        int i;

        FilterQuery query = new FilterQuery();

        if (users.size() > 0) {
            long[] follow = new long[users.size()];
            i = 0;
            for (User u : users) {
                follow[i] = u.getId();
                i++;
            }
            query.follow(follow);
        }

        if (terms.size() > 0) {
            String[] track = new String[terms.size()];
            i = 0;
            for (String s : terms) {
                track[i] = s;
                i++;
            }
            query.track(track);
        }

        if (null != locations) {
            query.locations(locations);

            /*
            double [][] loc = {{ 51.280430, -0.563160 },{ 51.683979, 0.278970 }}; // london
            double[][] loc = {{49.871159, -6.379880}, {55.811741, 1.768960}}; // england

View Full Code Here

TOP

Related Classes of twitter4j.FilterQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.