简体   繁体   English

如何使用流式Twitter API监视Java中的主题标签?

[英]How to use streaming twitter api to monitor an hashtag in java?

Can someone show me a java example? 有人可以给我看一个Java示例吗? I was looking for it, but I haven't found nothing 我一直在寻找,但是什么也没发现

This is actually quite easy, you must provide the hash tag in your track POST parameter: 这实际上很容易,您必须在track POST参数中提供hash标签:

The TwitterClient on github.com is a Java example of using the streaming API... it needs some work, most importantly the HttpURL needs changing to HttpsURL in TwitterClient.java: 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());
}

and Change http://stream.twitter.com/ to https://stream.twitter.com/ in example/Example.java . 并将example/Example.java http://stream.twitter.com/更改为https://stream.twitter.com/

Get TwitterClient from http://github.com/gistinc/TwitterClient once you have it compiled run the example like this: 编译后,从http://github.com/gistinc/TwitterClient获取TwitterClient,请运行以下示例:

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

In CURL, make a file with this in called track.txt : 在CURL中,用以下文件创建一个文件,即track.txt

track=#YourHashTag

Then run curl like this... you can see it working: 然后像这样运行curl,您可以看到它正在工作:

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

Hope this helps ;-) 希望这可以帮助 ;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM