我想按位置和语言过滤 Twitter 流。但面临错误。
我使用了链接中提到的位置参数 Passing Longitude and Latitude in Twitter Streaming API of Pakistan
错误: 7924 [Twitter Stream Consumer-1[建立连接]] 警告 twitter4j.TwitterStreamImpl - 角色不接受参数。 406:当请求中指定的格式无效时,由搜索 API 返回。
当一个或多个参数不适合资源时,由 Streaming API 返回。例如,如果出现以下情况,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"}));
.
请帮我看看我哪里错了?
最佳答案
尝试阅读Passing Longitude and Latitude in Twitter Streaming API of Pakistan再次。
它清楚地表明,为了正确给出框坐标,您需要采用以下格式:左下经度、左下纬度、右上经度、右上纬度。
这意味着西、南、东、北。
你有:
double locationsPakistan[][] = {{eastLongitude, southLatitude}
,{westLongitude, northLatitude}};
尝试:
double locationsPakistan[][] = {{westLongitude, southLatitude}
,{eastLongitude, northLatitude}};
更新
根据您在代码编辑后的评论,您现在拥有:
double northLatitude = 35.2;
double southLatitude = 25.2;
double eastLongitude = 62.9;
double westLongitude = 73.3;
double bb[][] = {{eastLongitude, southLatitude},{westLongitude, northLatitude}};
您混淆了东/西左/右。
您的评论显示了这一点,因为您有“东经/左经度。标记左侧边界。”
东是右侧边界。 同样,西边是左侧边界。 西应该是<东。
所以这样做:
double northLatitude = 35.2;
double southLatitude = 25.2;
double westLongitude = 62.9;
double eastLongitude = 73.3;
double bb[][] = {{westLongitude, southLatitude},{eastLongitude, northLatitude}};
关于java - 巴基斯坦 Twitter 流纬度和经度框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25562574/