0

嘿,我希望将某些用户的最新推文显示在我的网络应用程序的页面上。所以我遵循了关于horsebird 客户端 git的教程,但我不知道我必须在哪里指定我想要消息的用户。

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 吗?你能给我举一个白宫推特(https://twitter.com/whitehouse)的例子吗?

4

1 回答 1

1

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

hosebirdEndpoint.followings(userIds);

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

这里,您可以找到关于端点的 Twitter 文档,以及您可以使用的参数的完整列表。

于 2015-06-28T13:48:37.803 回答