I want get the information of user geolocation in twitter using Twitter4J.
I use tweet.getUser.getLocation()
but that gives me the wrong geolocation.
// create ConfigurationBuilder class variables "cb"
// Create Twitter Factory
TwitterFactory twitterFactory = new TwitterFactory(cb.build());
Twitter twitter = twitterFactory.getInstance();
try {
Query query = new Query("범죄");
QueryResult result;
int twittNum = 1;
do {
result = twitter.search(query);
List<Status> tweets = result.getTweets();
for (Status tweet : tweets) {
System.out.println("===========================================================================================================");
System.out.println("["+twittNum+"] 번째 트윗");
System.out.println("유저이름1:"+tweet.getUser().getName());
System.out.println("트윗장소:"+tweet.getUser().getLocation());
System.out.println("트윗언어:"+tweet.getUser().getLang());
System.out.println("트윗시간?:"+tweet.getUser().getCreatedAt());
System.out.println("===========================================================================================================");
twittNum++;
}
} while ((query = result.nextQuery()) != null);
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to search tweets: " + te.getMessage());
System.exit(-1);
}
}
What do you mean by wrong location?
Twitter4j is just an implementation on Java of the Twitter APi, and from the documentation:
location: Nullable. The user-defined location for this account’s profile. Not necessarily a location nor parseable. This field will occasionally be fuzzily interpreted by the Search service.
That means that tweet.getUser.getLocation()
will get you the location from the user and it is not a geolocation (like on some tweets). You can't get the real location from an user, the location field is an input from the user (an string
), so it could be anything. If you get stuffs like in your heart, below the bridge or something not so specific like Korea or the world that doesn't mean that is wrong, it just what people wrote.