我在哪里指定我想在twitter hbc中关注的用户

时间:2015-06-27 12:47:37

标签: twitter twitter4j twitter-streaming-api twitter-hbc

嘿我想收到某些用户的最新推文,我将关注这些推文显示在我的网页应用的页面上。所以我按照git of horsebird client上的教程,但我不知道在哪里必须指定我想要消息的用户。

public class TwitterLatestTweets implements Runnable {
    private final static String BUNDLE_BASENAME = "configuration.twitter";
    private final static String CONSUMER_KEY = ResourceBundle.getBundle(
            BUNDLE_BASENAME).getString("consumerKey");
    private final static String CONSUMER_SECRET = ResourceBundle.getBundle(
            BUNDLE_BASENAME).getString("consumerSecret");
    private final static String TOKEN = ResourceBundle.getBundle(
            BUNDLE_BASENAME).getString("token");
    private final static String SECRET = ResourceBundle.getBundle(
            BUNDLE_BASENAME).getString("secret");
    private List<String> msgList = new ArrayList<String>();

    @Override
    public void run() {
        /**
         * Set up your blocking queues: Be sure to size these properly based on
         * expected TPS of your stream
         */
        BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>(100000);
        BlockingQueue<Event> eventQueue = new LinkedBlockingQueue<Event>(1000);

        /**
         * Declare the host you want to connect to, the endpoint, and
         * authentication (basic auth or oauth)
         */
        Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST);

        StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();

        Authentication hosebirdAuth = new OAuth1(CONSUMER_KEY, CONSUMER_SECRET,
                TOKEN, SECRET);

        ClientBuilder builder = new ClientBuilder().hosts(hosebirdHosts)
                .authentication(hosebirdAuth).endpoint(hosebirdEndpoint)
                .processor(new StringDelimitedProcessor(msgQueue))
                .eventMessageQueue(eventQueue);

        Client hosebirdClient = builder.build();
        hosebirdClient.connect();
        while (!hosebirdClient.isDone()) {
            try {
                String msg = msgQueue.take();
                msgList.add(msg);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            hosebirdClient.stop();

            for (String s : msgList) {
                System.out.println(s);
            }
        }
    }
}

是Constants.STREAM_HOST吗?你能给我一个关于白宫twitter(https://twitter.com/whitehouse)的例子吗?

1 个答案:

答案 0 :(得分:1)

您需要向端点添加userIds列表,如下所示:

hosebirdEndpoint.followings(userIds);

您在问题中提供的同一github项目中有几个示例hereThis one使用与帖子中相同的端点。

here中,您可以在端点上找到Twitter的文档,以及可以使用的参数的完整列表。