1
votes

I want to filter twitter streams by location and language. But facing error.

I have used location parameter mentioned in link Passing Longitude and Latitude in Twitter Streaming API of Pakistan

Error : 7924 [Twitter Stream consumer-1[Establishing connection]] WARN twitter4j.TwitterStreamImpl - Parameter not accepted with the role. 406:Returned by the Search API when an invalid format is specified in the request.

Returned by the Streaming API when one or more of the parameters are not suitable for the resource. The track parameter, for example, would throw this error if:

The track keyword is too long or too short.

The bounding box specified is invalid.

No predicates defined for filtered resource, for example, neither track nor follow parameter defined.

Follow userid cannot be read.

No filter parameters found. Expect at least one parameter: follow track locations

    LinkedBlockingQueue<Status> queue = new LinkedBlockingQueue<Status>(1000);
    SpoutOutputCollector _collector = collector;
    StatusListener listener = new StatusListener() {

        @Override
        public void onStatus(Status status) {
            System.out.println(status.getLang());
            System.out.println(status.getPlace());
            System.out.print(status.getText());
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        @Override
        public void onTrackLimitationNotice(int i) {
        }

        @Override
        public void onScrubGeo(long l, long l1) {
        }

        @Override
        public void onException(Exception e) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
            // TODO Auto-generated method stub

        }

    };


    TwitterStreamFactory fact = new TwitterStreamFactory(new ConfigurationBuilder().setUser(_username).setPassword(_pwd).build());
    TwitterStream _twitterStream = fact.getInstance();
    _twitterStream.addListener(listener);

    ArrayList<Long> follow = new ArrayList<Long>();
    ArrayList<String> track = new ArrayList<String>();

    long[] followArray = new long[follow.size()];
    String[] trackArray = track.toArray(new String[track.size()]);

    /**
    * Upper/northern latitude that marks the
    * upper bounds of the geographical area
    * for which tweets need to be analysed.
    */
    double northLatitude = 35.2;
    /**
    * Lower/southern latitude. Marks the lower bound.
    */
    double southLatitude = 25.2;
    /**
    * Eastern/left longitude. Marks the left-side bounds.
    */
    double eastLongitude = 62.9;
    /**
    * Western/right longitude. Marks the right-side bounds.
    */
    double westLongitude = 73.3;


    double bb[][] = {{eastLongitude, southLatitude}
    ,{westLongitude, northLatitude}};


    _twitterStream.filter(new FilterQuery(0, followArray,trackArray,bb,new String[]{"en-US"}));


     .

Please help me where am i wrong?

1
Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See How to create a Minimal, Complete, and Verifiable example. - DavidPostill
I have upload partial code. Because this code were using in Storm. And Storm code is too large. My problem is that, FilterQuery send error that location is invalid. But I have mentioned location boundry box. Are you getting my point? - Ishwar Lal
@IshwarLal did u get tweets from Pakistan? what did you added in follow array ? - kashifmehmood
@kashifmehmood i have leave them empty as written above in code. - Ishwar Lal

1 Answers

2
votes

Try reading Passing Longitude and Latitude in Twitter Streaming API of Pakistan again.

It clearly says In order to give the box co-ordinates correctly you need to have them in the format bottom-left-longitude, bottom-left-latitude, top-right-longitude, top-right-latitude.

That means west, south, east north.

You have:

double locationsPakistan[][] = {{eastLongitude, southLatitude}
    ,{westLongitude, northLatitude}};

Try:

double locationsPakistan[][] = {{westLongitude, southLatitude}
    ,{eastLongitude, northLatitude}};

Update

As per your comment after your code edits you now have:

double northLatitude = 35.2;
double southLatitude = 25.2;
double eastLongitude = 62.9;
double westLongitude = 73.3;

double bb[][] = {{eastLongitude, southLatitude},{westLongitude, northLatitude}};

You are mixing up East/West Left/Right.

Your comments show this as you have "Eastern/left longitude. Marks the left-side bounds."

East is the right side bound. Similarly West is the left side bound. West should be < East.

So do this:

double northLatitude = 35.2;
double southLatitude = 25.2;
double westLongitude = 62.9;
double eastLongitude = 73.3;

double bb[][] = {{westLongitude, southLatitude},{eastLongitude, northLatitude}};