V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
MakisuCruse
V2EX  ›  问与答

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

  •  
  •   MakisuCruse · 2017-03-22 10:38:22 +08:00 · 696 次点击
    这是一个创建于 2756 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码如下,从队列 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();
        }
    }
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2282 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:22 · PVG 18:22 · LAX 03:22 · JFK 06:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.