我正在尝试从我对 TwitterAPI 提出的请求中保存一些数据。我知道,我必须在 UpdateTweetsService 类中设置我想要的对象,但我现在知道如何解析它们。这是我到目前为止所拥有的:
UpdateTweetsService.java 类:
import javax.inject.Inject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.social.twitter.api.Tweet;
import org.springframework.social.twitter.api.Twitter;
import java.util.List;
public class UpdateTweetsService {@Value("${screenName}")
private final Twitter twitter;
@Inject
public UpdateTweetsService(Twitter twitter) {
this.twitter = twitter;
}
/**
* Performs a Request to get the UserTimeline from Twitter API
*/
public List<Tweet> tweets() {
return twitter.timelineOperations().getUserTimeline("${screenName}");
}
Tweet.java 类:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;
@Entity
@Table(name = "tweets")
public class Tweet {
@Id
@GeneratedValue
@Column(columnDefinition = "INT unsigned")
private Integer id;
@NotEmpty
@Length(max = 255)
@Column(columnDefinition = "VARCHAR(255)", length = 255, nullable = false)
private String profileImageUrl;
@NotEmpty
@Length(max = 64)
@Column(columnDefinition = "VARCHAR(64)", length = 64, nullable = false)
private String fromUser;
@NotEmpty
@Column(columnDefinition = "TEXT", nullable = false)
private String text;
@NotEmpty
@Length(max = 255)
@Column(columnDefinition = "VARCHAR(255)", length = 255, nullable = false)
private String url;
@NotEmpty
@Column(columnDefinition = "FLOAT")
private Float createDate;
/*
* Getter & Setter
*/
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getProfileImageUrl() {
return profileImageUrl;
}
public void setProfileImageUrl(String profileImageUrl) {
this.profileImageUrl = profileImageUrl;
}
public String getFromUser() {
return fromUser;
}
public void setFromUser(String fromUser) {
this.fromUser = fromUser;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Float getCreateDate() {
return createDate;
}
public void setCreateDate(Float createDate) {
this.createDate = createDate;
}
}