【发布时间】:2014-10-23 03:05:35
【问题描述】:
我想按位置和语言过滤 twitter 流。但面临错误。
我使用了链接中提到的位置参数 Passing Longitude and Latitude in Twitter Streaming API of Pakistan
错误: 7924 [Twitter Stream consumer-1[Establishing connection]] WARN twitter4j.TwitterStreamImpl - 角色不接受参数。 406:当请求中指定了无效格式时,由 Search API 返回。
当一个或多个参数不适合资源时由 Streaming API 返回。例如,track 参数会在以下情况下抛出此错误:
track 关键字太长或太短。
指定的边界框无效。
没有为过滤的资源定义谓词,例如,既不跟踪也不跟随 参数定义。
无法读取关注用户ID。
未找到过滤器参数。至少需要一个参数:跟踪轨道位置
LinkedBlockingQueue<Status> queue = new LinkedBlockingQueue<Status>(1000);
SpoutOutputCollector _collector = collector;
StatusListener listener = new StatusListener() {
@Override
public void onStatus(Status status) {
System.out.println(status.getLang());
System.out.println(status.getPlace());
System.out.print(status.getText());
}
@Override
public void onDeletionNotice(StatusDeletionNotice sdn) {
}
@Override
public void onTrackLimitationNotice(int i) {
}
@Override
public void onScrubGeo(long l, long l1) {
}
@Override
public void onException(Exception e) {
}
@Override
public void onStallWarning(StallWarning arg0) {
// TODO Auto-generated method stub
}
};
TwitterStreamFactory fact = new TwitterStreamFactory(new ConfigurationBuilder().setUser(_username).setPassword(_pwd).build());
TwitterStream _twitterStream = fact.getInstance();
_twitterStream.addListener(listener);
ArrayList<Long> follow = new ArrayList<Long>();
ArrayList<String> track = new ArrayList<String>();
long[] followArray = new long[follow.size()];
String[] trackArray = track.toArray(new String[track.size()]);
/**
* Upper/northern latitude that marks the
* upper bounds of the geographical area
* for which tweets need to be analysed.
*/
double northLatitude = 35.2;
/**
* Lower/southern latitude. Marks the lower bound.
*/
double southLatitude = 25.2;
/**
* Eastern/left longitude. Marks the left-side bounds.
*/
double eastLongitude = 62.9;
/**
* Western/right longitude. Marks the right-side bounds.
*/
double westLongitude = 73.3;
double bb[][] = {{eastLongitude, southLatitude}
,{westLongitude, northLatitude}};
_twitterStream.filter(new FilterQuery(0, followArray,trackArray,bb,new String[]{"en-US"}));
.
请帮我看看我哪里错了?
【问题讨论】:
-
寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及重现它所需的最短代码在问题本身。没有明确的问题陈述的问题对其他读者没有用处。见How to create a Minimal, Complete, and Verifiable example。
-
我已经上传了部分代码。因为这段代码在 Storm 中使用。而且 Storm 代码太大。我的问题是,FilterQuery 发送位置无效的错误。但我已经提到了位置边界框。你明白我的意思了吗?
-
@IshwarLal 你收到来自巴基斯坦的推文了吗?你在跟随数组中添加了什么?
-
@kashifmehmood 我已将它们留空,如上面在代码中所写。
标签: java twitter location latitude-longitude