Java 使用twitterapi从Tweet获取坐标

Java 使用twitterapi从Tweet获取坐标,java,mongodb,twitter,unirest,Java,Mongodb,Twitter,Unirest,我正在尝试使用twitterapi和Java从tweet中正确获取信息。我正在尝试获取启用地理标记的精确坐标 从现在起,我已经按照指示创建了相应的Java类,但可能我对地理对象的理解不是很好,因为坐标、边界框或位置都没有出现。我的猜测是,我没有正确地声明这些类 对于Tweet类: // Imports here public class Tweet { @SerializedName("created_at") public String created_at; @

我正在尝试使用twitterapi和Java从tweet中正确获取信息。我正在尝试获取启用地理标记的精确坐标

从现在起,我已经按照指示创建了相应的Java类,但可能我对地理对象的理解不是很好,因为
坐标
边界框
位置
都没有出现。我的猜测是,我没有正确地声明这些类

对于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;
}
// 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;

}
对于坐标类:

// 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;
}
// 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;

}
对于Place类:

// 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;
}
// 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;

}
当我请求从链接的tweet中获取json信息时,我得到了以下数据,正如您所看到的,
坐标
位置
字段没有出现。如果有用的话,我将使用MongoDB Java API来存储json文件及其Java POJO管理器。您可以在此处找到所有代码:

{
“_id”:数字长(“1212893878430420992”),
“创建时间”:“Fri Jan 03 00:30:09+0000 2020”,
“收藏夹计数”:0,
“偏爱”:错误,
“id_街”:“1212893878430420992”,
“is_quote_status”:false,
“郎”:“恩”,
“可能敏感”:错,
“报价状态id”:编号长(0),
“引用的状态id str”:编号长(0),
“回复计数”:0,
“转发计数”:0,
“转发”:错误,
“来源”:“,
“文本”:“测试1”,
“截断”:“假”,
“用户”:{
“_id”:长号码(593955589),
“创建时间”:“2012年5月29日星期二18:59:38+0000”,
“默认配置文件”:false,
“默认_配置文件_图像”:false,
“描述”:“在电信技术领域的技术创新研究中,我们的技术创新是成功的。”,
“最受欢迎人数”:7497,
“粉丝数”:186,
“朋友数”:114,
“身份证号码”:“593955589”,
“列出的数量”:5,
“地点”:“萨拉曼卡/托莱多/马德里”,

“名称”:“Martín当我请求状态时,它具有该状态的正确字段

阅读“Tweet with Twitter Place”和“Tweet with exact location”之间的区别


我怀疑是您的“暂时”字段导致Mongo没有保存此字段。

您是否尝试使用Twitter4J()而不是自己映射api?没有,因为我想有一个更“低级”的控件,但似乎最后我必须使用它…(我不知道如何使用Twitter4J和MongoDB)您的推文可能在JSON数据中没有该信息。twitter用户必须选择加入以存储该数据。请查看developer.twitter.com