如何在 Twitter4j 中获取用户地理位置?
How to get user geolocation in Twitter4j?
我想使用 Twitter4J 在 twitter 中获取用户地理位置信息。
我使用 tweet.getUser.getLocation()
但这给了我错误的地理位置。
// 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);
}
}
错误的位置是什么意思?
Twitter4j 只是 Twitter APi Java 上的一个实现,来自 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.
这意味着 tweet.getUser.getLocation()
将从用户那里获取位置,而不是 地理定位 (如某些推文)。您无法从用户那里获得真实位置,位置字段是用户的输入(string
),因此它可以是任何东西。如果你得到诸如 in your heart、below the bridge 之类的东西,或者一些不太具体的东西,比如 Korea 或世界这并不意味着那是错误的,这只是人们写的。
我想使用 Twitter4J 在 twitter 中获取用户地理位置信息。
我使用 tweet.getUser.getLocation()
但这给了我错误的地理位置。
// 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);
}
}
错误的位置是什么意思?
Twitter4j 只是 Twitter APi Java 上的一个实现,来自 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.
这意味着 tweet.getUser.getLocation()
将从用户那里获取位置,而不是 地理定位 (如某些推文)。您无法从用户那里获得真实位置,位置字段是用户的输入(string
),因此它可以是任何东西。如果你得到诸如 in your heart、below the bridge 之类的东西,或者一些不太具体的东西,比如 Korea 或世界这并不意味着那是错误的,这只是人们写的。