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
感謝,
大衛
例如運行此代碼,我從-4.65842064鳴叫,55.40764413這是在塞舌爾的時候....所以顯然,我的邏輯是錯誤的地方爲我的邊界框應該是{{49.186288,-16.043709}, {57.186288,0.043709}}?並且這條推文應該在其外面 –