我正在尝试使用Twitter API和Java从推文中正确获取信息。我正在尝试从this tweet中获取启用了地理标记的确切坐标。
[从现在开始,我按照documentation的指示创建了相应的Java类,但是由于coordinates
,bounding_box
或place
都没有出现,所以我可能不太了解Geo对象。我的猜测是我没有正确声明这些类。
对于Tweet类:
// Imports here
public class Tweet {
@SerializedName("created_at")
public String created_at;
@SerializedName("id")
public long id;
// ... All the rest of the parameters
@SerializedName("coordinates")
public Coordinates coordinates;
@SerializedName("place")
public transient Place place;
对于坐标类:
// Imports here
public class Coordinates {
@SerializedName("coordinates")
public String coordinates;
@SerializedName("type")
public String type;
}
对于Place类:
// Imports here
public class Place {
@SerializedName("id")
public String id;
@SerializedName("url")
public String url;
// ... All the rest of the parameters
@SerializedName("bounding_box")
public String bounding_box;
}
[当我请求从链接的推文中获取json信息时,我得到以下数据,并且您可以看到coordinates
或places
字段未出现。如果有用,我正在使用MongoDB Java API来存储json文件及其Java POJO管理器。您可以在此处找到所有代码:https://github.com/marmatsan/theTrainEngine
{
"_id" : NumberLong("1212893878430420992"),
"created_at" : "Fri Jan 03 00:30:09 +0000 2020",
"favorite_count" : 0,
"favorited" : false,
"id_str" : "1212893878430420992",
"is_quote_status" : false,
"lang" : "en",
"possibly_sensitive" : false,
"quoted_status_id" : NumberLong(0),
"quoted_status_id_str" : NumberLong(0),
"reply_count" : 0,
"retweet_count" : 0,
"retweeted" : false,
"source" : "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>",
"text" : "Test 1",
"truncated" : "false",
"user" : {
"_id" : NumberLong(593955589),
"created_at" : "Tue May 29 18:59:38 +0000 2012",
"default_profile" : false,
"default_profile_image" : false,
"description" : "En búsqueda del verdadero camino del Tao estudiando Ingeniería en Tecnologías de Telecomunicación.",
"favourites_count" : 7497,
"followers_count" : 186,
"friends_count" : 114,
"id_str" : "593955589",
"listed_count" : 5,
"location" : "Salamanca/Toledo/Madrid",
"name" : "Martín 👾",
"profile_banner_url" : "https://pbs.twimg.com/profile_banners/593955589/1513111580",
"profile_image_url_https" : "https://pbs.twimg.com/profile_images/1130587021678927874/50unsAd3_normal.png",
"protected_att" : false,
"screen_name" : "MMateos97",
"statuses_count" : 19420,
"url" : "https://github.com/marmatsan",
"verified" : false
}
}
当我请求状态时,它具有此状态的正确字段。
$ okurl https://api.twitter.com/1.1/statuses/show/1212893878430420992.json
...
"geo":null,
"coordinates":null,
"place":{"id":"fd110fb449209bc4","url":"https:\/\/api.twitter.com\/1.1\/geo\/id\/fd110fb449209bc4.json","place_type":"city","name":"Burguillos de Toledo"
https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/geo-objects#tweet-exact
阅读“使用Twitter Place的推特”和“使用精确位置的推特”之间的区别。
我怀疑您的“临时”字段导致Mongo不保存此字段。