大家好,
public static void main(String[] args) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setOAuthConsumerKey("xxxxxx");
cb.setOAuthConsumerSecret("xxxx");
cb.setOAuthAccessToken("xxxx");
b.setOAuthAccessTokenSecret("xxxxxxx");
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
StatusListener listener = new StatusListener() {
@Override
public void onException(Exception arg0) {
// TODO Auto-generated method stub
}
@Override
public void onDeletionNotice(StatusDeletionNotice arg0) {
// TODO Auto-generated method stub
}
@Override
public void onScrubGeo(long arg0, long arg1) {
// TODO Auto-generated method stub
}
@Override
public void onStatus(Status status) {
User user = status.getUser();
// gets Username
String username = status.getUser().getScreenName();
System.out.println(username);
String profileLocation = user.getLocation();
System.out.println(profileLocation);
long tweetId = status.getId();
System.out.println(tweetId);
String content = status.getText();
System.out.println(content +"\n");
GeoLocation geolocation = status.getGeoLocation();
System.out.println(geolocation +"\n");
}
@Override
public void onTrackLimitationNotice(int arg0) {
// TODO Auto-generated method stub
System.out.println("onTrackLimitationNotice" +"\n");
}
@Override
public void onStallWarning(StallWarning arg0) {
// TODO Auto-generated method stub
System.out.println("onStallWarning" +"\n");
}
};
FilterQuery fq = new FilterQuery();
double lat = 53.186288;
double longitude = -8.043709;
double lat1 = lat - 4;
double longitude1 = longitude - 8;
double lat2 = lat + 4;
double longitude2 = longitude + 8;
twitterStream.addListener(listener);
double[][] bb= {{lat1,longitude1}, {lat2 ,longitude2}};
// fq.track(keywords);
fq.locations(bb);
twitterStream.filter(fq);
}
此代码用于在英国和爱尔兰的一般位置收集推文,但不收集推文,或者有时(很少)从边界框外的区域收集推文。
如果我扩大边界框,我确实会收到推文,但有时它们会在边界框之外。
我的工作逻辑是边界框的第一个点是 SW 角,下一个点是 NE 角。
任何想法可能是什么问题?我正在使用 Twitter4j 3.0.3
谢谢,
大卫