0

有人可以给我看一个java例子吗?我一直在寻找它,但我什么也没找到

4

1 回答 1

0

这实际上很简单,您必须在trackPOST 参数中提供哈希标记:

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/in example/Example.java

编译后获取 TwitterClient,http://github.com/gistinc/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

希望这可以帮助 ;-)

于 2011-12-30T19:23:27.093 回答