【问题标题】:How to use streaming twitter api to monitor an hashtag in java?如何使用流式 twitter api 监控 java 中的主题标签?
【发布时间】:2011-06-27 09:30:21
【问题描述】:

谁能给我看一个java例子?我一直在寻找它,但我什么也没找到

【问题讨论】:

    标签: java twitter-streaming-api


    【解决方案1】:

    这其实很简单,你必须在track POST 参数中提供哈希标签:

    github.com 上的 TwitterClient 是一个使用流 API 的 Java 示例...它需要一些工作,最重要的是 HttpURL 需要更改为 TwitterClient.java 中的 HttpsURL:

    /**
     * Extracts the host and post from the baseurl and constructs an
     * appropriate AuthScope for them for use with HttpClient.
     */
    private AuthScope createAuthScope(String baseUrl) throws URIException {
        //HttpURL url = new HttpURL(baseUrl);
        HttpsURL url = new HttpsURL(baseUrl);
        return new AuthScope(url.getHost(), url.getPort());
    }
    

    并将http://stream.twitter.com/ 中的https://stream.twitter.com/ 更改为example/Example.java

    http://github.com/gistinc/TwitterClient 获取 TwitterClient 编译后运行如下示例:

    java <classpathstuff> example.Example username:password -t #YourHashTag
    

    在 CURL 中,创建一个名为 track.txt 的文件:

    track=#YourHashTag
    

    然后像这样运行 curl ......你可以看到它工作:

    curl https://stream.twitter.com/1/statuses/filter.json -uusername:password -d @track.txt
    

    希望这会有所帮助;-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-18
      • 2012-08-15
      • 1970-01-01
      • 2017-11-15
      • 2011-10-30
      • 2015-11-17
      • 1970-01-01
      • 2012-10-21
      相关资源
      最近更新 更多