2

I'm trying to use the Twitter hbc library to get tweets based on locations. I've set up my code according to the example file FilterStreamExample. The example works, but when I try to add a location to the endpoint, I get Fatal error code: 406.

Here's the code that works:

StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
endpoint.trackTerms(Lists.newArrayList("twitterapi", "#yolo"));

But when I add the following code, I get the error:

Coordinate southwest = new Coordinate(-87.648926, 41.883109);
Coordinate northeast = new Coordinate(-87.606354, 41.828050);
Location chicago = new Location(southwest, northeast); 
endpoint.locations(Lists.newArrayList(chicago));

Thanks for the help!

Greg

EDIT Here's the entirety of my code:

public class App {

  public static void oauth(String consumerKey, String consumerSecret, String token, String secret) throws InterruptedException {
    BlockingQueue<String> queue = new LinkedBlockingQueue<String>(100000);

    StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
    Coordinate southwest = new Coordinate(-87.857666, 41.657347);
    Coordinate northeast = new Coordinate(-87.587128, 41.795712);
    Location chicago = new Location(southwest, northeast); 
    endpoint.locations(Lists.newArrayList(chicago));

    Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret);

    BasicClient client = new ClientBuilder()
      .name("exampleStream")
      .hosts(Constants.STREAM_HOST)
      .endpoint(endpoint)
      .authentication(auth)
      .processor(new StringDelimitedProcessor(queue))
      .build();

    // Establish a connection
    client.connect();
    PrintWriter writer;
    try {
      writer = new PrintWriter("twitterstream.txt", "UTF-8"); 
// Do whatever needs to be done with messages
      for (int msgRead = 0; msgRead < 1000; msgRead++) {
        if (client.isDone()) {
          System.out.println("Client connection closed unexpectedly: " + client.getExitEvent().getMessage());
          break;
      }
      String msg = queue.poll(5, TimeUnit.SECONDS);
      if (msg == null) {
        System.out.println("Did not receive a message in 5 seconds");
      } else {
        writer.println(msg);
      }
    }
     writer.close();
        } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
      e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
      e.printStackTrace();
        }  

        client.stop();
}

  public static void main(String[] args) {
  try {
      App.oauth("LEDrJPDhn6C2trbde95WZg", "gEmlgewUodOoDjMNl2QbcqsbGvYDxNZWNRULchPE", "292576546-SWzEgMU7mC7Haat3lLEOQ0mXsZFwBf8F3ZKLBMVa", "ajPN2rGLx57yPoUjYe2qN4bE763orux4KwYeoCAvuLRPM");
  } catch (InterruptedException e) {
      System.out.println(e);
  }

}

user1801348
  • 55
  • 1
  • 5
  • I ran your code, Tweets were written to the file and I didn't see any error. Does the error happen straight away? Can you add the details of the error/stack-track to the question please? BTW, you should probably revoke your API tokens now they are publicly available. – Jonathan Nov 08 '13 at 08:49
  • hm..looks like maybe it's a credentials thing (although it's weird that it would work with the first query and not the second)...thanks for the help, though! – user1801348 Nov 08 '13 at 15:56

3 Answers3

2

Maybe the problem be the coordinates. You should verify on http://boundingbox.klokantech.com/. Choose the option "csv" after that to delimit the place.

anapaulagomes
  • 335
  • 4
  • 11
  • You are right, I verified the points I was trying to lookup using this site and figured out that I was using them in the wrong order. – Arar Sep 21 '17 at 20:17
1

Are you using Google Map coordinate ? Because It seems that you should switch your coordinate point.

Coordinate southwest = new Coordinate(41.657347, -87.857666);
Coordinate northeast = new Coordinate(41.795712, -87.587128);

You may also use the hbc snapshot version https://github.com/twitter/hbc/issues/19 Regards.

Ratinahirana
  • 392
  • 2
  • 9
0

I have checked your code with yours and mine Outh parameters. With mine it works and it doesnt work with yours. This is the problem

EK.
  • 2,890
  • 9
  • 36
  • 49