[英]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 实现,来自文档:
位置:可为空。 此帐户配置文件的用户定义位置。 不一定是位置也不是可解析的。 搜索服务有时会模糊地解释此字段。
这意味着tweet.getUser.getLocation()
将从用户那里获取位置,而不是地理位置(如某些推文)。 您无法从用户那里获取真实位置,位置字段是来自用户的输入( string
),因此它可以是任何内容。 如果你心里有一些东西,在桥下,或者像韩国或世界那样不那么具体的东西,这并不意味着这是错误的,那就是人们写的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.