MakisuCruse
V2EX  ›  问与答

twitter hbc 访问 streaming api 没有响应数据

  •  
  •   MakisuCruse · Mar 22, 2017 · 967 views
    This topic created in 3340 days ago, the information mentioned may be changed or developed.

    代码如下,从队列 take 数据一直阻塞

    public class FilterStreamExample {
        public static void main(String[] args) throws InterruptedException {
            run("consumerKey", "consumerSecret", "token", "secret");
        }
        public static void run(String consumerKey, String consumerSecret, String token, String secret) throws InterruptedException {
            BlockingQueue<String> queue = new LinkedBlockingQueue<String>(10000);
            StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
            endpoint.trackTerms(Lists.newArrayList("twitterapi", "#yolo"));
            Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret);
            Client client = new ClientBuilder()
                    .hosts(Constants.STREAM_HOST)
                    .endpoint(endpoint)
                    .authentication(auth)
                    .processor(new StringDelimitedProcessor(queue))
                    .build();
            client.connect();
            for (int msgRead = 0; msgRead < 1000; msgRead++) {
                String msg = queue.take();
                System.out.println(msg);
            }
            client.stop();
        }
    }
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   905 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:58 · PVG 04:58 · LAX 13:58 · JFK 16:58
    ♥ Do have faith in what you're doing.