Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

yes..... i got track from user stream on HBC, plz confirm this approach is correct or not. #73

Closed
farahnaj opened this issue May 30, 2013 · 1 comment

Comments

@farahnaj
Copy link

yes.. i got track from user stream on HBC, plz confirm this code is right or wrong, because i am new user of hbc. This is working code, I got right result, with keyword search. plz just confirm my approach is right or wrong or it may give some problem in certain scenario. thank you.


public class UserStreamExample
{
public static void oauth(String consumerKey, String consumerSecret, String token, String secret) throws InterruptedException
{
BlockingQueue queue = new LinkedBlockingQueue(10000);

        UserstreamEndpoint endpoint = new UserstreamEndpoint();
        endpoint.addQueryParameter("track","farah");

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

        // Create a new BasicClient. By default gzip is enabled.
        Client client = new ClientBuilder()
          .hosts(Constants.USERSTREAM_HOST)
          .endpoint(endpoint)
          .authentication(auth)
          .processor(new StringDelimitedProcessor(queue))
          .build();

        // Establish a connection
        client.connect();

        // Do whatever needs to be done with messages
        for (int msgRead = 0; msgRead < 1000; msgRead++) {
          String msg = queue.take();
          System.out.println(msg);
        }

        client.stop();
 }

 public static void main(String[] args) {
      try {
          UserStreamExample.oauth(args[0], args[1], args[2], args[3]);
      } catch (InterruptedException e) {
          System.out.println(e);
      }
  }

}


@kevinoliver
Copy link
Contributor

That looks legit to me. You can also use StatusesFilterEndpoint.trackTerms(List) instead of UserstreamEndpoint.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants